mons.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..orm.hibernate3.HibernateTempla te$16.doInHibernate(HibernateTemplate.java:686)
at org..orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:369)
at org..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)
Hello MrCodeMan,
why do you choose a native id generator, when hibernate is not supposed to set the id!
Have you tried not to use a generator, which means the id is manually set/hibernate doesn't touch it.
HTH
Cheers,
Oh, and callable=true is only for stored procedures, see Hibernate Documentation
Cheers,
I tried removing the generator and get the following error:
org..orm.hibernate3.HibernateSystem Exception: ids for this class must be manually assigned before calling save(): com.emerald_associates.p3eqb.hibernate.TimeTrackin g; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.emerald_associates.p3eqb.hibernate.TimeTrackin g
Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.emerald_associates.p3eqb.hibernate.TimeTrackin g
Ok, I'm sorry, I misunderstood the thing with the hibernate id and not using a generator.
Hibernate is right with the exception, in that case you must provide the id yourself. So that's not what you want, I assume.
Sorry for leading you in the wrong direction.
What you would need is the generator class=select, see Hibernate Docs.
But there's another problem arising with this, you need a unique surrogate/natural key in the table which hibernate selects the new id from.
Perhaps you could use TxnDate (if it is unique).
e.g.:
Code:
lt;id ...gt; lt;generator class=quot;selectquot;gt; lt;param name=quot;keyquot;gt;txnDatelt;/paramgt; lt;/generatorgt;
lt;/idgt;
This would also mean, that you do not need that special lt;sql-insertgt;.
Thanks for your suggestion.
I was able to use a temporary fix by setting another field (txnDate) to the id and then setting txnID to a property and dynamic-insert=quot;truequot; for the class. This way, because txnID is null and is a property, it doesn't appear in the insert statement. But this obviously isn't a good way to solve the problem.
Your suggestion sounds more best-practice-like. But txnDate isn't always unique. I guess I could append the current time to the notes field to make it unique and use that as the surrogate id. It's the only field that is editable.
I guess the real problem is that I believe my Quickbooks file is using MS Access as the underlying database, but there is no dialect available for Access. For my purposes, I just need to do a simple insert so I thought I could just use another dialect like SQL Server, but the insert fails because it is appending a select identity to the end of the insert. If I could suppress that Select that appends to end of the insert then I could use another dialect. Using lt;generator class=quot;selectquot;gt; won't help in my case, because I don't want the TxnID showing up in the Insert statement. The Quickbooks ODBC driver does not allow the ID to be set on the Insert. The dialect and type of generator is supposed to handle this, but since I don't want a generator in my case.
It seems really complex, to trick hibernate into not adding the id into an insert, but getting the id afterwards - the select generator really has it's drawbacks.
Some options i could think of:You could try to implement your own dialect or generator, though i'm not an expert on how to achieve this.
If you really know it is an Access DB you could try the Access ODBC driver. Then the id insert shouldn't be a problem anymore.
If you're not restricted to use hibernate, take a look at iBATIS SQL Maps.
It's way simpler then hibernate in handling existing database structures, because you use native SQL to perform database operations.
Cheers,
I think there's a link on here for an MS Access dialect but you have to pay for it.
80.html
i used Ibatis as awurzer suggested and it was not difficult to use. I have no trouble with the insert statements now. Thanks. |