I'm trying to execute an HQL Delete, but hibernate complains about some ',' in the HQL command.
Here's a test:
Code:
public static void main(String[] args) {
Session s = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction t = s.beginTransaction();
t.begin();
UsuarioGrupoDAO ugDAO = new UsuarioGrupoDAO();
ugDAO.deleteByHQL("delete UsuarioGrupo usuariorGrp"+
" where usuariorGrp.usuario.idusuario = 77"+
" and usuariorGrp.grupo.idgrupo in (3)"+
" and usuariorGrp.grupo.cxpostal.idcxpostal = 2");
t.commit();
}
Hibernate version: Hibernate 3.1.3
Full stack trace of any exception that occurs:xception 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
Name and version of the database you are using:MS SQL SERVER 2000
The generated SQL (show_sql=true):DEBUG SQL:346 - delete from vanpix.dbo.usuario_grupo, vanpix.dbo.grupo grupo1_ where idusuario=77 and (idgrupo in (3)) and idcxpostal=2
Hibernate: delete from vanpix.dbo.usuario_grupo, vanpix.dbo.grupo grupo1_ where idusuario=77 and (idgrupo in (3)) and idcxpostal=2
Debug level Hibernate log excerpt:Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.htmlCode: