Hibernate 3.1.3 is generating invalid SQL for some HQL statements (on SQLServer).
Mappings:
Code:
<class name="com.something.ParentTable" table="ParentTable">
<composite-id>
<key-property name="value1" type="int" column="value1"/>
<key-property name="value2" type="int" column="value2"/>
</composite-id>
<property name="name" type="string" column="name"/>
<set name="children" inverse="true">
<key>
<column name="value1" />
<column name="value2" />
</key>
<one-to-many class="com.something.ChildTable"/>
</set>
</class>
<class name="com.something.ChildTable" table="ChildTable">
<composite-id>
<key-many-to-one name="parentTable" class="com.something.ParentTable" lazy="false">
<column name="value1"/>
<column name="value2"/>
</key-many-to-one>
<key-property name="purpose" type="string" column="purpose"/>
</composite-id>
<property name="anotherValue" type="java.lang.String" column="anotherValue" />
<property name="lastModified" type="java.util.Date" column="lastModified" />
<property name="modifiedBy" type="java.lang.String" column="modifiedBy" />
<property name="inactiveDate" type="java.util.Date" column="inactiveDate" />
</class>
Java Code:
Code:
getHibernateTemplate().bulkUpdate("update ChildTable set inactiveDate = '2007-01-12 10:09:28.095' where parentTable.value1 = 0 and parentTable.value2 = 0");
Stack Trace:
Quote:
10:09:28.111 WARN!! [SocketListener0-0] org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:71) >59> SQL Error: 170, SQLState: HY000
10:09:28.111 ERROR! [SocketListener0-0] org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:72) >59> [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect syntax near ','.
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute update query; uncategorized SQLException for SQL [update ChildTable, set inactiveDate='2007-01-12 10:09:28.095' where value1=0 and value2=0]; SQL state [HY000]; error code [170]; [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect syntax near ','.; nested exception is java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect syntax near ','.
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect syntax near ','.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
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 org.springframework.orm.hibernate3.HibernateTemplate$40.doInHibernate(HibernateTemplate.java:1072)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.bulkUpdate(HibernateTemplate.java:1063)
at org.springframework.orm.hibernate3.HibernateTemplate.bulkUpdate(HibernateTemplate.java:1055)
at com.something.MyDAODatabase.setInactive(MyDAODatabase.java:189)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy12.delete(Unknown Source)
at com.something.MyBusiness.setInactive(MyBusiness.java:210)
For some reason, it is inserting a comma after the table name, and so HQL:
Code:
update ChildTable set inactiveDate = '2007-01-12 10:09:28.095' where parentTable.value1 = 0 and parentTable.value2 = 0
becomes SQL:
Code:
update ChildTable, set inactiveDate='2007-01-12 10:09:28.095' where value1=0 and value2=0
Any ideas?