Hello Everyone,
I want to retrieve the data in DB. If the data is not present i.e., if retrieve gives null, I should insert into DB if data is present i.e., if retrieve is not null , I should update the data that is already present.
But the insertion is trying to happen twice for which i get the following exception:
ERROR [2011-10-07 03:16:36] [Thread-12] (JDBCExceptionReporter.java:72) - Duplicate key or integrity constraint violation message from server: "Duplicate entry '10.50.34.36-ASN AAA Resume Trap' for key 'PRIMARY'"
ERROR [2011-10-07 03:16:36] [Thread-12] (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.NMSDBAlarmCRUD.insert(NMSDBAlarmCRUD.java:117)
at com.tel.Fault.NMSFaultEventHandler.handleEvent(NMSFaultEventHandler.java:129)
at com.tel.Fault.NMSFaultEventHandler.run(NMSFaultEventHandler.java:156)
Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Duplicate entry '10.50.34.36-ASN AAA Resume Trap' 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)
... 10 more
The retreive method is as follows:
Here the argument is alarmList of type NMSDBAlarmList. NMSDBAlarmList have getter and setter methods.
This DB has composite key which is got by getAlarmListPK. Using which I try retrieve and is stored in alarmList which is an object of NMSDBAlarmList.
This should actually return null only once in order to insert, where as other times it should give the data present in order to update.
But getting null more than once.
Any solutions or suggestions would be of great help
Thanks in advance
I want to retrieve the data in DB. If the data is not present i.e., if retrieve gives null, I should insert into DB if data is present i.e., if retrieve is not null , I should update the data that is already present.
But the insertion is trying to happen twice for which i get the following exception:
ERROR [2011-10-07 03:16:36] [Thread-12] (JDBCExceptionReporter.java:72) - Duplicate key or integrity constraint violation message from server: "Duplicate entry '10.50.34.36-ASN AAA Resume Trap' for key 'PRIMARY'"
ERROR [2011-10-07 03:16:36] [Thread-12] (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.NMSDBAlarmCRUD.insert(NMSDBAlarmCRUD.java:117)
at com.tel.Fault.NMSFaultEventHandler.handleEvent(NMSFaultEventHandler.java:129)
at com.tel.Fault.NMSFaultEventHandler.run(NMSFaultEventHandler.java:156)
Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Duplicate entry '10.50.34.36-ASN AAA Resume Trap' 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)
... 10 more
The retreive method is as follows:
Here the argument is alarmList of type NMSDBAlarmList. NMSDBAlarmList have getter and setter methods.
This DB has composite key which is got by getAlarmListPK. Using which I try retrieve and is stored in alarmList which is an object of NMSDBAlarmList.
This should actually return null only once in order to insert, where as other times it should give the data present in order to update.
But getting null more than once.
Any solutions or suggestions would be of great help
Thanks in advance