insert.
I am going to cry.
I dont know what to do with this.
i have A with many to one with B . cascade is all
B has many to many (idbag)with C.
B and C PK is assigned by the application
A_DAO::
Code:
Session session = TransactionManager.getConnection();
session.saveOrUpdate(queryEvent);
TransactionManager.close(true);
in case of failure - rollback.
session is on threadlocal
when i call to single thread that send a lot of A with the same B (B exists in the DB)
it is ok.
but when i run multi threads that send a lot of A with the same B
hibernate after some time try to delete B before insert (why, why,why).
This cause to this exception:
Code:
org.hibernate.exception.LockAcquisitionException: could not delete collection: [com.mercado.s2002.analysis.objects.CriteriaDictionary.Criterion#-231454997]
....
Caused by: org.hibernate.exception.LockAcquisitionException: could not delete collection: [com.mercado.s2002.analysis.objects.CriteriaDictionary.Criterion#-231454997]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:82)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:1023)
at org.hibernate.action.CollectionRemoveAction.execute(CollectionRemoveAction.java:28)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
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:993)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.mercado.s2002.analysis.util.TransactionManager.commit(TransactionManager.java:230)
at com.mercado.s2002.analysis.util.TransactionManager.close(TransactionManager.java:370)
at com.mercado.s2002.analysis.dao.hibernate.QueryEventDAO.save(QueryEventDAO.java:59)
... 38 more
Caused by: java.sql.SQLException: Deadlock found when trying to get lock; try restarting transaction
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1124)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:676)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1166)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1082)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1067)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:1011)
... 50 more
when i try to save again. i get:
Code:
org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1
Please advice.