Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi, I have a tableA where am trying to modify 2 different instances from tableA. That trying to modify row1 and row2. field 'reference' is unique. I aim is to make a copy of row1's reference then delete row1 and finally update row2's reference with that of deleted row1's reference. I got a duplicate key violate unique constraint. But am using the same hibernate session to do the updates, hibernate should know that row1 has been deleted. can anyone please explain me why this is so.
thanks in advance
[b]Hibernate version:3.1.3[/b]
[b]Mapping documents:[/b]
[b]Code between sessionFactory.openSession() and session.close():
HibernateUtil.beginTransaction();
TableA a1 = TableA.get(id1);
String ref = a.getReference();
TableA a2 = TableA.get(id2);
HibernateUtil.currentSession().delete(a1);
a2.setReference(ref);
HibernateUtil.currentSession().update(a2);
HibernateUtil.commitTransaction();
[/b]
[b]Full stack trace of any exception that occurs:
2006-08-14 11:08:54,519 : JDBCExceptionReporter.logExceptions : SQL Error: 0, SQLState: null
2006-08-14 11:08:54,534 : JDBCExceptionReporter.logExceptions : Batch entry 0 update tableA set reference=tuitui, type_id=1 where id=82
90104 was aborted. Call getNextException to see the cause.
2006-08-14 11:08:54,534 : JDBCExceptionReporter.logExceptions : SQL Error: 0, SQLState: 23505
2006-08-14 11:08:54,534 : JDBCExceptionReporter.logExceptions : ERROR: duplicate key violates unique constraint "reference_key"
2006-08-14 11:08:54,534 : AbstractFlushingEventListener.performExecutions : 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:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
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.JTATransaction.commit(JTATransaction.java:135)
at com.gloptv.saga.server.tools.HibernateUtil.commitTransaction(HibernateUtil.java:205)
[/b]
[b]Name and version of the database you are using:postgresql 8[/b]
[b]The generated SQL (show_sql=true):[/b]
[b]Debug level Hibernate log excerpt:[/b]