Alguém aí já conseguiu executar um comando de HQL de Delete do Hibernate com um NOT IN??
Isso por exemplo, não funciona…mas o select dele sim.
delete from UsuarioGrupo ug
where ug.usuario.idusuario = 77
and ug.grupo.idgrupo not in(1)
and ug.grupo.cxpostal.idcxpostal = 2
O Select:
select ug.grupo.grpNome from UsuarioGrupo ug
where ug.usuario.idusuario = 77
and ug.grupo.idgrupo not in(1)
and ug.grupo.cxpostal.idcxpostal = 2
Ao executar o HQL com delete ele dá um erro:
15:38:45,234 DEBUG SQL:346 - delete from vanpix.dbo.usuario_grupo, vanpix.dbo.grupo grupo1_ where idusuario=77 and (idgrupo not in (1)) and idcxpostal=2
Hibernate: delete from vanpix.dbo.usuario_grupo, vanpix.dbo.grupo grupo1_ where idusuario=77 and (idgrupo not in (1)) and idcxpostal=2
15:38:45,281 WARN JDBCExceptionReporter:71 - SQL Error: 170, SQLState: 37000
15:38:45,281 ERROR JDBCExceptionReporter:72 - Line 1: Incorrect syntax near ','.
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:334)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:209)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1126)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at com.pix.hibernate.entities.grupo.BaseHibernateDAO.deleteByHQL(BaseHibernateDAO.java:45)
at com.pix.tests.HibernateTests.main(HibernateTests.java:24)
Caused by: java.sql.SQLException: Line 1: Incorrect syntax near ','.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:505)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 6 more
Alguém já passou por isso? Sabem algum workaround?