I'm using Spring with Hibernate for a connection to an odbc (Quickbooks QODBC). There is no dialect that matches the database so I am using the HSQLDialect. It works fine for running queries but when I try to perform an insert, the id for the table record is being set to null. I'm not supposed to set the id on the insert, so I want to override the Hibernate generated Insert statement with my own. But when I try to use <sql-insert> in the hbm.xml file, it's not being called because Hibernate is still generating the id in the insert statement and setting it to null. I'm calling it using:
timeTrackingDao.saveOrUpdate(timeTrackingRecord);
which is calling:
public void saveOrUpdate(Object obj) {
getHibernateTemplate().saveOrUpdate(obj);
}
Do I have to do something to get it to override the Hibernate generated SQL so it calls my custom sql? The class mapping and error is shown below.
<class name="com.emerald_associates.p3eqb.hibernate.TimeT racking" dynamic-insert="true" table="TimeTracking" lazy="false">
<id name="txnID" column="TxnID" unsaved-value="0">
<generator class="native"/>
</id>
<property name="txnDate" column="TxnDate"/>
<property name="entityRefListID" column="EntityRefListID"/>
<property name="entityRefFullName" column="EntityRefFullName"/>
<property name="customerRefListID" column="CustomerRefListID"/>
<property name="customerRefFullName" column="CustomerRefFullName"/>
<property name="itemServiceRefListID" column="ItemServiceRefListID"/>
<property name="itemServiceRefFullName" column="ItemServiceRefFullName"/>
<property name="durationMinutes" column="DurationMinutes"/>
<property name="classRefListID" column="ClassRefListID"/>
<property name="classRefFullName" column="ClassRefFullName"/>
<property name="notes" column="Notes"/>
<property name="timeCreated" column="TimeCreated"/>
<sql-insert callable="true">
INSERT INTO TimeTracking (CustomerRefListID, CustomerRefFullName, EntityRefListID, EntityRefFullName,
ItemServiceRefListID, ItemServiceRefFullName, ClassRefListID, ClassRefFullName,
DurationMinutes, TxnDate)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
</sql-insert>
</class>
Hibernate: insert into TimeTracking (TxnDate, EntityRefListID, EntityRefFullName, ItemServiceRefListID, ItemServiceRefFullName, DurationMinutes, ClassRefListID, ClassRefFullName, TxnID) values (?, ?, ?, ?, ?, ?, ?, ?, null)
java.sql.SQLException: [QODBC] Field not allowed in insert.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(JdbcOdbc.java:31 50)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Jd bcOdbcPreparedStatement.java:214)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpd ate(JdbcOdbcPreparedStatement.java:136)
at org.apache.commons.dbcp.DelegatingPreparedStatemen t.executeUpdate(DelegatingPreparedStatement.java:9 4)
at org.hibernate.id.insert.AbstractSelectingDelegate. performInsert(AbstractSelectingDelegate.java:33)
at org.hibernate.persister.entity.AbstractEntityPersi ster.insert(AbstractEntityPersister.java:2158)
at org.hibernate.persister.entity.AbstractEntityPersi ster.insert(AbstractEntityPersister.java:2631)
at org.hibernate.action.EntityIdentityInsertAction.ex ecute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQue ue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener. performSaveOrReplicate(AbstractSaveEventListener.j ava:298)
at org.hibernate.event.def.AbstractSaveEventListener. performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener. saveWithGeneratedId(AbstractSaveEventListener.java :107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.saveWithGeneratedOrRequestedId(DefaultSaveO rUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.entityIsTransient(DefaultSaveOrUpdateEventL istener.java:172)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.performSaveOrUpdate(DefaultSaveOrUpdateEven tListener.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.onSaveOrUpdate(DefaultSaveOrUpdateEventList ener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(Se ssionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(Sessio nImpl.java:499)
at org.hibernate.impl.SessionImpl.saveOrUpdate(Sessio nImpl.java:495)
at org.springframework.orm.hibernate3.HibernateTempla te$16.doInHibernate(HibernateTemplate.java:686)
at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:369)
at org.springframework.orm.hibernate3.HibernateTempla te.saveOrUpdate(HibernateTemplate.java:683)
at com.emerald_associates.p3eqb.hibernate.HibernateTi meTrackingDao.saveOrUpdate(HibernateTimeTrackingDa o.java:96)
at com.emerald_associates.p3eqb.quickbooks.Main.main( Main.java:243)
|