如何使用 Glassfish 2.1 在 JPA 中实现悲观锁定?
当尝试使用以下代码设置锁定(悲观)时:
em.lock(controlnumbers, LockModeType.WRITE);
em.refresh(controlnumbers);
我收到以下异常:
[#|2009-09-10T15:42:48.324-0400|INFO|sun-appserver2.1|javax.enterprise.system.container.ejb|_ThreadID=31;_ThreadName=httpSSLWorkerThread-8080-19;|
javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: javax.persistence.PersistenceException: ejb30-wrong-lock_called_without_version_locking-index (There is no English translation for this message.)
javax.persistence.PersistenceException: ejb30-wrong-lock_called_without_version_locking-index (There is no English translation for this message.)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.lock(EntityManagerImpl.java:619)
at com.sun.enterprise.util.EntityManagerWrapper.lock(EntityManagerWrapper.java:582)
at com.eximtechnologies.transactionserver.persistence.session.ControlNumbersFacade.lock(ControlNumbersFacade.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
How can I Implement pessimisticlocking with Glassfish 2.1?
When trying to setup a lock (pessimistic), with the following code:
em.lock(controlnumbers, LockModeType.WRITE);
em.refresh(controlnumbers);
I am getting the following exception:
[#|2009-09-10T15:42:48.324-0400|INFO|sun-appserver2.1|javax.enterprise.system.container.ejb|_ThreadID=31;_ThreadName=httpSSLWorkerThread-8080-19;|
javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: javax.persistence.PersistenceException: ejb30-wrong-lock_called_without_version_locking-index (There is no English translation for this message.)
javax.persistence.PersistenceException: ejb30-wrong-lock_called_without_version_locking-index (There is no English translation for this message.)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.lock(EntityManagerImpl.java:619)
at com.sun.enterprise.util.EntityManagerWrapper.lock(EntityManagerWrapper.java:582)
at com.eximtechnologies.transactionserver.persistence.session.ControlNumbersFacade.lock(ControlNumbersFacade.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
How can I implement pessimistic locking with Glassfish 2.1?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个 Toplink Essentials(GF 2.1 默认)特定的方法可以做到这一点:
我相信 Hibernate 调用 em.lock 实际上会起作用。
There is a Toplink Essentials (GF 2.1 default) specific way to do this:
I believe with Hibernate calling em.lock will actually work.
你能展示一下你的班级的映射吗?看起来您缺少版本属性...看看
http:// en.wikibooks.org/wiki/Java_Persistence/Locking#Timestamp_Locking
问候,Jan
Can you show the mapping for your class? It looks like you are missing a version property... Take a look at
http://en.wikibooks.org/wiki/Java_Persistence/Locking#Timestamp_Locking
Regards, Jan