Results 1 to 1 of 1
- 06-05-2011, 07:43 PM #1
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Hibernate - ConstraintViolationException, the best way to handle this is?
We want to have the option to add staffnumbers manual in the application.
You can set the Id in the application.
When i set an Id that already exists i get a ConstraintViolationException. I'm trying to catch it but it doesn't work, because i still get it.
What is the best way to handle this problem. It's Hibernate database communication.
Error:Java Code:public static boolean insertStaff(Staff s){ boolean result = false; try { Session session = NewHibernateUtil.getSessionFactory().openSession(); Transaction transaction = session.beginTransaction(); transaction.begin(); session.save(s); transaction.commit(); result = true; } catch (ConstraintViolationException ex) { System.out.println(ex.getMessage() + ex.getClass() ); return false; } return result; }
SEVERE: Duplicate entry '2' for key 'PRIMARY'
5-jun-2011 19:36:26 org.hibernate.event.def.AbstractFlushingEventListe ner performExecutions
Could not execute JDBC batch updateclass org.hibernate.exception.ConstraintViolationExcepti on
SEVERE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationExcepti on: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:298)
at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1000)
at org.hibernate.impl.SessionImpl.managedFlush(Sessio nImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(J DBCTransaction.java:106)
at Database.DatabaseConnectie.insertStaff(DatabaseCon nectie.java:663)
at Controller.Controller.AddStaff(Controller.java:405 )
Similar Threads
-
best way to handle db connection
By uthpalaw in forum Advanced JavaReplies: 11Last Post: 02-18-2011, 06:00 AM -
a new way to handle exceptions
By brodie in forum Web FrameworksReplies: 10Last Post: 01-20-2010, 04:50 PM -
Handle sound
By varsamakos in forum AWT / SwingReplies: 4Last Post: 12-26-2009, 09:40 PM -
Better way to handle exceptions
By javaplus in forum Advanced JavaReplies: 2Last Post: 01-16-2008, 06:47 PM -
org.hibernate.ejb.Version <clinit> INFO: Hibernate EntityManager 3.2.0.CR1
By Heather in forum JDBCReplies: 2Last Post: 06-30-2007, 03:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks