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.  [ 3 posts ] 
Author Message
 Post subject: lockmode on projected entity doesn't work
PostPosted: Tue Feb 14, 2006 5:38 am 
Newbie

Joined: Fri Oct 28, 2005 9:08 am
Posts: 12
Hello, I have a problem to lock a row in database when I use a projection of the entity --> nullPointerException !

Hibernate version: 3.1

Code between sessionFactory.openSession() and session.close():

Criteria criteria = this.getSession().createCriteria(object.getClass());
criteria.setProjection(Projections.projectionList()
.add(Projections.property("nummsg"))
.add(Projections.property("numref"))
.add(Projections.property("libmsg1")));
criteria.setLockMode(LockMode.READ);
return criteria.list().iterator();

+ transaction management

Full stack trace of any exception that occurs:

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.loader.criteria.CriteriaLoader.applyLocks(CriteriaLoader.java:135)
at org.hibernate.loader.Loader.preprocessSQL(Loader.java:189)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1552)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1492)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
at com.cwsoft.commons.model.dao.hibernate.GenericDaoHibernateImpl.getByKey(GenericDaoHibernateImpl.java:57)
at com.cwsoft.commons.model.service.impl.ServiceImpl.service(ServiceImpl.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy1.service(Unknown Source)
at com.cwsoft.commons.test.TestGenericDao.main(TestGenericDao.java:54)


Name and version of the database you are using:
Oracle 9


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 1:44 pm 
Newbie

Joined: Thu Mar 23, 2006 10:52 am
Posts: 4
I'm having the same problem with Hibernate 3.1.3. Did you end up solving yours?

For the curious:

I stepped through the hibernate code in the debugger. The NullPointerException in CriteriaLoader.applyLocks happens because its local "entityAliases" array is null; that array is null because the "aliases" field (defined in OuterJoinLoader) is null. So the question is, where did (or should) OuterJoinLoader.aliases come from? Well, it comes from a method called initFromWalker(JoinWalker walker), which calls walker.getAliases().

So now the question is, what's up with this JoinWalker? In this case, it is a CriteriaJoinWalker, which extends AbstractEntityJoinWalker.

Where, then, does (or should) JoinWalker.aliases get initalized? It happens in a method called initPersisters. This method, in turn, is called by the AbstractEntityJoinWalker.initAll method.

Why isn't CriteriaJoinWalker calling that initAll method? Here's the relevant code in the CriteriaJoinWalker constructor:

Code:
      if ( translator.hasProjection() ) {
         resultTypes = translator.getProjectedTypes();
         initProjection( ... );
      }
      else {
         resultTypes = new Type[] { ... };
         initAll( ... );
      }


So, when there's a projection, we don't call the initAll method, and so the aliases field is never initialized. As a newbie, I can't distinguish between the following possibilities:

1. It's not legal to use setLockMode and projections together.
2. It is legal, and the lack of initialization in this case is a bug.
3. It is legal, but we're doing it all wrong; a more experienced user would do [some clever thing].

Of course, even cases 1 and 3 are arguably bugs; NPE is not a helpful error message.


Top
 Profile  
 
 Post subject: Jira Issue Created
PostPosted: Thu May 29, 2008 3:55 pm 
Newbie

Joined: Wed Aug 25, 2004 11:16 pm
Posts: 12
Location: San Francisco, CA
We recently ran into this same issue. I've created an issue in Jira which includes 5 tests that demonstrate several queries that work and several more that do not (because of the NPE).

http://opensource.atlassian.com/project ... e/HHH-3313

Please watch (and vote on) the issue if you're interested in seeing it resolved.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.