This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes synchronize database state with session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "synchronize database state with session" Watch "synchronize database state with session" New topic
Author

synchronize database state with session

nami shekar
Greenhorn

Joined: Sep 14, 2011
Posts: 17
Hi All,
I am getting this exception when i try to do insertion to DB using Hibernate


The exception is as follows:
(JDBCExceptionReporter.java:72) - Duplicate key or integrity constraint violation message from server: "Duplicate entry '10.50.34.36-Authentication Failure' for key 'PRIMARY'"
ERROR [2011-09-14 01:17:45] [Thread-11] (AbstractFlushingEventListener.java:299) - 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:69)
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:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1007)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:354)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.tel.Database.DBAlarmCRUD.insert(NMSDBAlarmCRUD.java:110)
at com.tel.Fault.FaultEventHandler.handleEvent(NMSFaultEventHandler.java:100)
at com.tel.Fault.FaultTrapHandler.handleTrap(NMSFaultTrapHandler.java:62)
at com.tel.Fault.FaultTrapReceiver.run(NMSFaultTrapReceiver.java:204)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Duplicate entry '10.50.34.36-Authentication Failure' for key 'PRIMARY'"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)



And in the insert method at this line : transaction.commit(); the exception is shown.



Thanks in advance,

Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2504
    
    8

Welcome to the Ranch, Nami!


This is the direct cause of your problem:
Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Duplicate entry '10.50.34.36-Authentication Failure' for key 'PRIMARY'"


You, or your software, is trying to put the text '10.50.34.36-Authentication Failure' in a database field that requires that all values are unique, and that field already contains that text in another record. You are violating a primary key constraint.


OCUP UML fundamental and ITIL foundation
youtube channel
nami shekar
Greenhorn

Joined: Sep 14, 2011
Posts: 17
Hi Jan Cumps,
Thank you for your reply

Say suppose i have hundred data to be inserted into DB
50 or 60 may get inserted without any probelm, and later i get this problem.
And few times without any problem the code works fine. Why is it so?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2504
    
    8

I moved your thread to our Object Relational Mapping forum. That is the right place for Hibernate questions.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: synchronize database state with session