Hi,

If you have explicitly set the id in your SQL query then you have certainly screwed the internal counter for auto_increment. Ie MySQL thinks the next id to use is 100 but you have inserted it already.
Try to reset the increment value for the table in question ie

ALTER TABLE theTableInQuestion AUTO_INCREMENT=100 (assuming 100 is currently the highest of your ids)

make a backup of the table just in case...

hope this helps

Charles

On 9 Feb 2009, at 19:59, mettamara wrote:


Hello all,
Sorry to post a basic problem here, but have struggling with finding the answer and not sure if anyone has encountered something similar. Long story short is I had manually inserted an entry directly into a MySQL DB using SQL, the problem is when I attempt to save a new entity through AppFuse
using the generic hibernate DAO, the save method (which uses the
SaveOrUpdate) on entity throws a synch error/ duplicate key. The hibernate object being save has no Id set by the code and the entity Id is defined as:

        private Long campaignId;
       ...
        @Id @GeneratedValue(strategy = GenerationType.AUTO)
        public Long getCampaignId() {
                return campaignId;
        }

I have tried flushing and rebooting tomcat to get the session to resync, but no luck. Any one have any thoughts? Stack trace below (100 is the primary
key I entered manually):

ERROR (04:26:31,272) [TP-Processor3]
AbstractFlushingEventListener.performExecutions(301) | Could not synchronize
database state with session
org.hibernate.exception.ConstraintViolationException: could not insert:
[com.tig.app.model.AdCampaign]
       at
org .hibernate .exception.SQLStateConverter.convert(SQLStateConverter.java:71)
       at
org .hibernate .exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at
org .hibernate .id .insert .AbstractReturningDelegate .performInsert(AbstractReturningDelegate.java:40)
       at
org .hibernate .persister .entity.AbstractEntityPersister.insert(AbstractEntityPersister.java: 2163)
       at
org .hibernate .persister .entity.AbstractEntityPersister.insert(AbstractEntityPersister.java: 2643)
       at
org .hibernate .action .EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java: 51) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java: 279)
       at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
       at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
       at
org .hibernate .event .def .AbstractFlushingEventListener .performExecutions(AbstractFlushingEventListener.java:298)
       at
org .hibernate .event .def .DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
       at
org .springframework .orm .hibernate3 .HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
       at
org .springframework .orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java: 420)
       at
org .springframework .orm .hibernate3 .HibernateTemplate.executeWithNativeSession(HibernateTemplate.java: 374)
       at
org .springframework .orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:820)
       at
org .appfuse .dao.hibernate.GenericDaoHibernate.save(GenericDaoHibernate.java:95)
.....
Caused by:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
Duplicate entry '100' for key 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java: 931)
       at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
       at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
       at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
       at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
       at
com .mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java: 1268)
--
View this message in context: 
http://www.nabble.com/Manually-Inserted-Entity-and-GenericHibernate-DAO-synchronization-conflict-tp21919006s2369p21919006.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net
For additional commands, e-mail: users-h...@appfuse.dev.java.net


=====================================
Charles Girardot
European Molecular Biology Laboratory
C. Boulin and E. Furlong Groups
Tel: +49-6221-387-8426
Email: charles.girar...@embl.de
Room 502
Meyerhofstrasse 1 - Postfach 10.2209
69012 Heidelberg, Germany
=====================================





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net
For additional commands, e-mail: users-h...@appfuse.dev.java.net

Reply via email to