my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes Hibernate. Nested transactions. Lock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate. Nested transactions. Lock" Watch "Hibernate. Nested transactions. Lock" New topic
Author

Hibernate. Nested transactions. Lock

stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
I'm working with MySQL and I have 2 transaction, one is within the other.
External:
Inner transaction:
Class-helper, that works with Hibernate-transactions:
The inner transaction is committed. But when the external transaction is tried to be committed, we wait 100 seconds(this is configured in configuration of MySQL), then the exception is thrown. Here is the log that contains the error:
[19:44:40] jt.monty: Hibernate: select this_.id as id29_1_, this_.username as username29_1_, this_.password as password29_1_, this_.framedIP as framedIP29_1_, this_.framedMask as framedMask29_1_, this_.blocked as blocked29_1_, this_.checkHost as checkHost29_1_, this_.ipPool as ipPool29_1_, this_.lastConnection as lastConn9_29_1_, this_.service as service29_1_, service2_.id as id24_0_, service2_.status as status24_0_, service2_.begin as begin24_0_, service2_.end as end24_0_, service2_.serviceInfoId as serviceI5_24_0_, service2_.tariffPlanId as tariffPl6_24_0_, service2_.accountId as accountId24_0_ from RadiusAccount this_ inner join services service2_ on this_.service=service2_.id where this_.id=? and 1=1
Hibernate: select this_.id as id24_2_, this_.status as status24_2_, this_.begin as begin24_2_, this_.end as end24_2_, this_.serviceInfoId as serviceI5_24_2_, this_.tariffPlanId as tariffPl6_24_2_, this_.accountId as accountId24_2_, tariffplan2_.id as id4_0_, tariffplan2_.title as title4_0_, tariffplan2_.userCharge as userCharge4_0_, tariffplan2_.type as type4_0_, tariffplan2_.beginDate as beginDate4_0_, tariffplan2_.endDate as endDate4_0_, account3_.id as id12_1_, account3_.number as number12_1_, account3_.balance as balance12_1_, account3_.type as type12_1_, account3_.status as status12_1_ from services this_ left outer join tariffPlans tariffplan2_ on this_.tariffPlanId=tariffplan2_.id inner join accounts account3_ on this_.accountId=account3_.id where this_.id=? and 1=1
Hibernate: select tariffs0_.tariffPlanId as tariffPl4_1_, tariffs0_.id as id1_, tariffs0_.orderIndex as orderIndex1_, tariffs0_.id as id0_0_, tariffs0_.price as price0_0_, tariffs0_.title as title0_0_ from tariffs tariffs0_ where tariffs0_.tariffPlanId=?
Hibernate: select properties0_.tariffId as tariffId0_, properties0_.value as value0_, properties0_.property as property0_ from tariffProperties properties0_ where properties0_.tariffId=?
Hibernate: select this_.id as id85_0_, this_.status as status85_0_, this_.begin as begin85_0_, this_.end as end85_0_, this_.serviceInfoId as serviceI5_85_0_, this_.tariffPlanId as tariffPl6_85_0_, this_.accountId as accountId85_0_ from services this_ where this_.accountId=? and 1=1
Hibernate: insert into financialOperations (balance, description, operationSum, accountId, date) values (?, ?, ?, ?, ?)
Hibernate: insert into serviceExpences (price, saveDate, account, tariffPlan, service) values (?, ?, ?, ?, ?)
Hibernate: update accounts set number=?, balance=?, type=?, status=? where id=?
2009-10-06 20:42:35,031 WARN net.jradius.freeradius.FreeRadiusProcessor(5) [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 1205, SQLState: 41000
2009-10-06 20:42:35,031 ERROR net.jradius.freeradius.FreeRadiusProcessor(5) [org.hibernate.util.JDBCExceptionReporter] - Lock wait timeout exceeded; try restarting transaction
2009-10-06 20:42:35,031 ERROR net.jradius.freeradius.FreeRadiusProcessor(5) [org.hibernate.event.def.AbstractFlushingEventListener] - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not update: [model.entity.customer.account.Account#1]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2430)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2312)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2612)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:96)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:135)
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:72)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:905)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:715)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
at model.dao.TransactionManager.commit(TransactionManager.java:33)
at tariffication.TarifficationManagerImpl.saveData(TarifficationManagerImpl.java:67)
at tariffication.TarifficationManagerImpl.tariffy(TarifficationManagerImpl.java:32)
at radius.accounting.SessionUpdater.tariffySession(SessionUpdater.java:24)
at radius.accounting.processor.SessionUpdateProcessor.proccessSession(SessionUpdateProcessor.java:26)
at radius.controller.impl.AccountingController.handleRequest(AccountingController.java:26)
at radius.RadiusRequestHandler.handle(RadiusRequestHandler.java:18)
at radius.dispatcher.RadiusRequestDispatcher.handle(RadiusRequestDispatcher.java:24)
at net.jradius.handler.PacketHandlerBase.handle(PacketHandlerBase.java:49)
at net.jradius.handler.EventHandlerBase.execute(EventHandlerBase.java:66)
at net.jradius.server.RadiusProcessor.runPacketHandlers(RadiusProcessor.java:130)
at net.jradius.freeradius.FreeRadiusProcessor.processRequest(FreeRadiusProcessor.java:57)
at net.jradius.server.Processor.process(Processor.java:123)
at net.jradius.server.Processor.run(Processor.java:99)
Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2408)
... 28 more
Maybe someone can help me? I don't even know the source of the problem...
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
My TransactionManager has field "nextedTransactionAllowed". But when I set it "true", nothing changes.
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
The problem was not about nested transactions. Some operation with database were simply performed in other connection.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate. Nested transactions. Lock