-->
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.  [ 7 posts ] 
Author Message
 Post subject: Custom Identifier Generator For String Column But no seq num
PostPosted: Wed Apr 23, 2008 9:50 am 
Newbie

Joined: Mon Dec 18, 2006 1:16 am
Posts: 9
Hibernate version:3.1
DB2


How to generate a Id for String column?


I have written one custom generator class which extends TableHiLoGenerator

There is no seq number for that column.

But I got Exception like..

org.hibernate.exception.SQLGrammarException: could not get or update next value
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.engine.TransactionHelper$1Work.doWork(TransactionHelper.java:41)
at org.hibernate.engine.transaction.Isolater$JdbcDelegate.delegateWork(Isolater.java:153)
at org.hibernate.engine.transaction.Isolater.doIsolatedWork(Isolater.java:38)
at org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:51)
at org.hibernate.id.TableGenerator.generate(TableGenerator.java:94)
at org.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:61)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at HibernateBasics.main(HibernateBasics.java:28)
Caused by: com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, SQLERRMC: EPDS.HIBERNATE_UNIQUE_KEY
at com.ibm.db2.jcc.b.sf.e(sf.java:1680)
at com.ibm.db2.jcc.b.sf.a(sf.java:1239)
at com.ibm.db2.jcc.c.jb.h(jb.java:139)
at com.ibm.db2.jcc.c.jb.a(jb.java:43)
at com.ibm.db2.jcc.c.w.a(w.java:30)
at com.ibm.db2.jcc.c.cc.f(cc.java:161)
at com.ibm.db2.jcc.b.sf.n(sf.java:1219)
at com.ibm.db2.jcc.b.tf.gb(tf.java:1816)
at com.ibm.db2.jcc.b.tf.d(tf.java:2298)
at com.ibm.db2.jcc.b.tf.X(tf.java:508)
at com.ibm.db2.jcc.b.tf.executeQuery(tf.java:491)
at org.hibernate.id.TableGenerator.doWorkInCurrentTransaction(TableGenerator.java:133)
at org.hibernate.engine.TransactionHelper$1Work.doWork(TransactionHelper.java:38)
... 15 more
Exception in thread "main"

Could anyone help ?

thank You
Selvaraj


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 23, 2008 3:48 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Hibernate must be thinking that you are still trying to use a sequence.
According to this

http://www.hibernate.org/hib_docs/v3/re ... -generator

you just have to create a class that implements org.hibernate.id.IdentifierGenerator

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: String ID automatic generation
PostPosted: Thu Apr 24, 2008 5:40 am 
Newbie

Joined: Mon Dec 18, 2006 1:16 am
Posts: 9
I have created class which implements Identifier Generator.
but still I am getting same exception.one thing is my table does not have sequence number and ID column is string .The requirement is ID should be automatically generated.So Is there any way to generate ID automatically for string column?.

Hibernate Version:3.1
DB2 Version
Thank You,
Selvaraj C


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 24, 2008 10:59 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
yes, use an "uuid' generator type, it will create that random 32-char unique String ID.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: 32 bit length restrict to 10
PostPosted: Thu Apr 24, 2008 1:05 pm 
Newbie

Joined: Mon Dec 18, 2006 1:16 am
Posts: 9
The UUIDHexGenerator is generating 32 character length my field length in DB is 10 due to that Data Exception is thrown.So anyway to trim or restrict the length?

The exception trace

org.hibernate.exception.DataException: could not insert: [Item]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2078)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at HibernateBasics.main(HibernateBasics.java:71)
Caused by: com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -302, SQLSTATE: 22001, SQLERRMC: null
at com.ibm.db2.jcc.b.sf.d(sf.java:1396)
at com.ibm.db2.jcc.c.jb.l(jb.java:367)
at com.ibm.db2.jcc.c.jb.a(jb.java:64)
at com.ibm.db2.jcc.c.w.a(w.java:48)
at com.ibm.db2.jcc.c.dc.b(dc.java:302)
at com.ibm.db2.jcc.b.tf.cb(tf.java:1719)
at com.ibm.db2.jcc.b.tf.d(tf.java:2319)
at com.ibm.db2.jcc.b.tf.d(tf.java:2458)
at com.ibm.db2.jcc.b.tf.Y(tf.java:540)
at com.ibm.db2.jcc.b.tf.executeUpdate(tf.java:523)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2062)

Thank You,
Selvaraj C


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 24, 2008 2:03 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Look at the bottom of the following link; it gives you a code example, plus the corresponding mapping file.

http://resource.visual-paradigm.com/vps ... rator.html

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: generate Id for string column length is <=10
PostPosted: Fri Apr 25, 2008 5:27 am 
Newbie

Joined: Mon Dec 18, 2006 1:16 am
Posts: 9
I have already gone through the same link.But my problem is filed length is 10 and UUID generated 32 character length due to this I got that exception.

Requirement is generate Id for string column length is <=10


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.