-->
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: problem of duplicate entry with 'increment' ID generator
PostPosted: Sat Sep 16, 2006 12:41 am 
Newbie

Joined: Sat Sep 16, 2006 12:04 am
Posts: 2
I use hibernate 2.1 with spring framework, and the database is mysql. Very occasionaly, I got duplicate entry error of duplicate entry. The persistence related code is as follows:
----------------------------------
public class HibernateDAO{
...........
public void save(Object o){
//o is a object with id of int type.
//The id is generated by Hibernate 'increment' ID generator
try{
getHibernateTemplate().save(o);
}catch(Exception ex){
Log.error(ex.getMessage());
}
}
...........
}
------------------------------------
It's initialized in spring in singleton mode. I think the 'increment' ID generator works fine definitely. I suspect HibernateDAO.save(Object) caused the problem in multithread environment, but I'm not sure. I do search many posts in Google reporting similiar issue, but no solution is found as far. :-(

------------------------------------
Here is the logging message:
------------------------------------
2006-08-21 17:20:49,925 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
2006-08-21 17:20:49,957 ERROR [org.hibernate.util.JDBCExceptionReporter] Duplicate entry '3699' for key 12006-08-21 17:20:49,958 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
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:993)
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)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 8:34 am 
Newbie

Joined: Sat Sep 16, 2006 12:04 am
Posts: 2
anybody?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 11:21 am 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
Well increment strategy works fine on a single ClassLoader (even in a multi-thread environment), and if no other application modifies data in database.

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


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.