-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: EntityManager.lock(Object,LockModeType.WRITE) always fails
PostPosted: Fri Oct 27, 2006 2:30 am 
Newbie

Joined: Tue Oct 17, 2006 11:58 pm
Posts: 2
Location: Whidbey Island, WA
The EntityManager.lock() method is non-functional when used with a LockModeType.WRITE. When calling the method I get the following exception trace:

    Exception in thread "main" java.lang.NullPointerException
    at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1290)
    at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:88)
    at org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:64)
    at org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:584)
    at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:576)
    at org.hibernate.ejb.AbstractEntityManagerImpl.lock(AbstractEntityManagerImpl.java:375)
    at Test.testEJB(Test.java:30)
    at Test.main(Test.java:19)


My test case is simple:

Code:
        Title title1 = entityManager.find(Title.class, "1");
        EntityTransaction transaction = entityManager.getTransaction();
        transaction.begin();
        entityManager.lock(title1, LockModeType.WRITE);
        System.out.println("testEJB: " + title1.getName());
        transaction.rollback();


The problem is fairly easily traced to the fact that in AbstractEntityManagerImpl.getLockMode() a LockModeType.WRITE is always converted into a LockMode.FORCE leading to the NullPointerException in AbstractEntityPersister.lock() when getLocker() returns a null because the "lockers" attribute does not have an entry for LockMode.FORCE because the line in AbstractEntityPersister.initLockers() that creates the LockMode.FORCE entry is commented out.

Uncommenting out the line appears to fix the problem (i.e., a reasonable "SELECT id from <table> where id =? for update" is generated.

This is using Hibernate Core/Annotations/EntityManager 3.2.0 GA.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 6:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This was a bug, it is fixed in 3.2.1

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 5:21 am 
Beginner
Beginner

Joined: Thu Jan 25, 2007 3:36 pm
Posts: 25
Hi

I'm also getting this same error, and I'm using versions > 3.2.1:

Code:
2007-05-14 09:36:36.950 INFO    org.hibernate.cfg.annotations.Version   Hibernate Annotations 3.3.0.GA
2007-05-14 09:36:36.963 INFO    org.hibernate.cfg.Environment   Hibernate 3.2.2
...snip...
2007-05-14 09:36:37.038 INFO    org.hibernate.ejb.Version       Hibernate EntityManager 3.3.0.GA


Is there anything else I can try?

The entity I'm trying to lock is not null and all relationships are initialized. The code that throws the exception is as follows:

Code:
EntityManager em = [snip]
em.lock( entity, LockModeType.WRITE );


The em.lock() throws:
Code:
java.lang.NullPointerException
        at org.hibernate.persister.entity.AbstractEntityPersister.lock(AbstractEntityPersister.java:1334)
        at org.hibernate.event.def.AbstractLockUpgradeEventListener.upgradeLock(AbstractLockUpgradeEventListener.java:88)
        at org.hibernate.event.def.DefaultLockEventListener.onLock(DefaultLockEventListener.java:64)
        at org.hibernate.impl.SessionImpl.fireLock(SessionImpl.java:584)
        at org.hibernate.impl.SessionImpl.lock(SessionImpl.java:576)
        at org.hibernate.ejb.AbstractEntityManagerImpl.lock(AbstractEntityManagerImpl.java:376)
        at [my calling code from this point down...]


Thanks
Darren


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 12:56 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Seems like the bug is a phoenix
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2613

But on the other hand why are you using LockModeType.WRITE on a non versioned entity?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 11:23 am 
Beginner
Beginner

Joined: Thu Jan 25, 2007 3:36 pm
Posts: 25
Sorry all - my bad.

Thanks Emmanuel - that was an oversight - we've added the <version /> to the ORM and it's all working now.

Darren


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.