[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2131?page=c...
]
Michel HAMON commented on HHH-2131:
-----------------------------------
Hi,
I think that:
MyClass myClass = (MyClass) session.get(MyClass.class,id));
session.lock(myClass,LockMode.UPGRADE);
doesn't work because 2 differents thread can execute "session.get", both
retrieve the same value.
I can't use hibernate.connection.isolation=4 because in this mode all select hold a
lock.
session.get("MyClass", id, LockMode.UPGRADE) should always lock the row, with
both Sybase AND Oracle.
With Sybase: session.get(MyClass.class, id, LockMode.UPGRADE) should generate something
like
update TableName set keyColumn=key where keyColumn=key
select * from TableName where keyColumn=key
instead of
select * from TableName holdlock where keyColumn=key
I think that Hibernate should run the same way with all database.
SYBASE +select for update is showing deadlock because lock is not
working properly
----------------------------------------------------------------------------------
Key: HHH-2131
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2131
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.1.3
Environment: sybaseASE 12.5.03 in solaris +hibernate3.1.3
Reporter: George Thomas
I am connecting to Sybase database from hibernate.I tried setting locks using while
selecting rows
1.session.load(class,id,LOCKMODE.UPGRADE)
2.session.lock(obj,LOCKMODE.UPGRADE)
I am attaching a sample code while updating a field in table fund after selecting it.
{
Fund fund = null;
ClientCredential credential = new ClientCredential("testDatabase", fund);
org.hibernate.Session session =
SessionFactoryManager.getSessionFactory(credential).getCurrentSession();
Transaction transaction = session.beginTransaction();
log.info("Run by " + Thread.currentThread().getName());
fund = (Fund) session.get(Fund.class, new Short((short)12), LockMode.UPGRADE);
fund.setLegalEntityOrgId(fund.getLegalEntityOrgId()+1);
transaction.commit();
}
my requirement was that i wanted to do a select for update.I should acquire lock on
certain rows and do a matching and if concurrent request comes ,it should wait till
transaction is over that is lock is released.
When I went through the hibernate code,the hibernate is making static queries in the
beginning while loading session factory.Since we are appending the holdlock during
execution,the sybase dialect is not appending.
As a work around I tested with native sql with holdlock but when I test concurrent
request using threads its bombing.Its throwing LockAcquisitionException.( Your server
command (family id #0, process id #3777) encountered a deadlock situation.).can anyone
give a solution to this problem???
org.hibernate.exception.LockAcquisitionException: could not update:
[com.citco.aexeo.common.dataaccess.domain.Fund#12]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:84)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2223)
at
org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2375)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:233)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
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:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:107)
at com.satyam.Testing.doTransaction(Testing.java:103)
at com.satyam.MyRunnable.run(MyRunnable.java:13)
at java.lang.Thread.run(Thread.java:568)
Caused by: com.sybase.jdbc2.jdbc.SybSQLException: Your server command (family id #0,
process id #3777) encountered a deadlock situation. Please re-run your command.
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2636)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1996)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:204)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:187)
at com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1642)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1625)
at
com.sybase.jdbc2.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatement.java:91)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2205)
... 14 more
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira