-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Using DB2 auto generated identity columns
PostPosted: Mon Jun 04, 2007 12:40 pm 
Newbie

Joined: Mon Jun 04, 2007 12:07 pm
Posts: 5
I have searched the FAQs and this forum so apologies if this is a common question. I have a DB2 (v8.2) table whose primary key is defined as follows

IND_ID integer primary key GENERATED ALWAYS AS IDENTITY

I have tried and failed to save the corresponding bean, no matter what I try. I have pasted the relevant snippets and log entries below. If anyone has experienced this problem and overcome it I would be most grateful if you could share your expertise.

1.
<id name="id" type="int" column="IND_ID"><generator class="identity"/></id>

Result: SQLException
"A value cannot be specified for column "IND_ID" which is defined as GENERATED ALWAYS"

2.
<id name="id" type="int" column="IND_ID"><generator class="native"/></id>

Result: SQLException
"KDUNN.HIBERNATE_SEQUENCE" is an undefined name.

3.
<id name="id" type="int" column="IND_ID"><generator class="increment"/></id>

Result: SQLException
A value cannot be specified for column "IND_ID" which is defined as GENERATED ALWAYS.

4.
<id name="id" type="int" column="IND_ID"><generator class="select"/></id>

Result: ear doesn't even start up but gives this message- org.hibernate.id.IdentifierGenerationException: no natural-id property defined; need to specify [key] in generator parameters

5.
<id name="id" column="IND_ID" type="int">
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="force_table_use">true</param>
<param name="value_column">IND_ID</param>
</generator>
</id>

Result:
org.hibernate.HibernateException: error performing isolated work
at org.hibernate.engine.transaction.Isolater$JtaDelegate.delegateWork(Isolater.java:142)
at org.hibernate.engine.transaction.Isolater.doIsolatedWork(Isolater.java:40)
at org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:51)
at org.hibernate.id.enhanced.TableStructure$1.getNextValue(TableStructure.java:72)
at org.hibernate.id.enhanced.OptimizerFactory$NoopOptimizer.generate(OptimizerFactory.java:90)
at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:157)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
at


Top
 Profile  
 
 Post subject: Re: Using DB2 auto generated identity columns
PostPosted: Tue Jun 05, 2007 1:08 am 
Newbie

Joined: Mon Dec 11, 2006 12:54 am
Posts: 14
kpdunn wrote:
I have searched the FAQs and this forum so apologies if this is a common question. I have a DB2 (v8.2) table whose primary key is defined as follows

IND_ID integer primary key GENERATED ALWAYS AS IDENTITY

I have tried and failed to save the corresponding bean, no matter what I try. I have pasted the relevant snippets and log entries below. If anyone has experienced this problem and overcome it I would be most grateful if you could share your expertise.

1.
<id name="id" type="int" column="IND_ID"><generator class="identity"/></id>

Result: SQLException
"A value cannot be specified for column "IND_ID" which is defined as GENERATED ALWAYS"

2.
<id name="id" type="int" column="IND_ID"><generator class="native"/></id>

Result: SQLException
"KDUNN.HIBERNATE_SEQUENCE" is an undefined name.

3.
<id name="id" type="int" column="IND_ID"><generator class="increment"/></id>

Result: SQLException
A value cannot be specified for column "IND_ID" which is defined as GENERATED ALWAYS.

4.
<id name="id" type="int" column="IND_ID"><generator class="select"/></id>

Result: ear doesn't even start up but gives this message- org.hibernate.id.IdentifierGenerationException: no natural-id property defined; need to specify [key] in generator parameters

5.
<id name="id" column="IND_ID" type="int">
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="force_table_use">true</param>
<param name="value_column">IND_ID</param>
</generator>
</id>

Result:
org.hibernate.HibernateException: error performing isolated work
at org.hibernate.engine.transaction.Isolater$JtaDelegate.delegateWork(Isolater.java:142)
at org.hibernate.engine.transaction.Isolater.doIsolatedWork(Isolater.java:40)
at org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:51)
at org.hibernate.id.enhanced.TableStructure$1.getNextValue(TableStructure.java:72)
at org.hibernate.id.enhanced.OptimizerFactory$NoopOptimizer.generate(OptimizerFactory.java:90)
at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:157)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
at



Hi,

You can try using the following :
<generator class="sequence">
<param name="sequence">IND_ID</param>
</generator>

Just add a surrogate key column to your table which will be uniquely identifying your table and then add corresponding column to your bean and mapping files as an id field..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 11:42 am 
Newbie

Joined: Mon Jun 04, 2007 12:07 pm
Posts: 5
Thanks for your reply.

We discovered today that the issue is doe to a bug in Hibernate 3.2.4 as highlighted in this post

http://forum.hibernate.org/viewtopic.ph ... 2+identity

After we installed the 3.2.4sp1 jars, simply specifying generator-class="identity" in the mapping file now works.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.