-->
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.  [ 4 posts ] 
Author Message
 Post subject: Errors with lazt attribute in "select new"
PostPosted: Sun Jun 29, 2008 9:22 pm 
Newbie

Joined: Thu Jun 26, 2008 12:50 am
Posts: 9
Hi,

We've got a problem where we are using "select new" to create a pojo that contains the results from a query that gathers summary information from the system. The query is simple getting a code and a count of unmatched rows in our DB:
Code:
final Query peerOrgCodeQuery = em.createQuery(
                    "select new com.synyati.spurwing.reconciliation.business."
                    + "ReconciliationSummaryUtil$PeerOrgCodeUpdate("
                    + "rbd.peerOrgCode, COUNT(*)) "
                    + "from ReconciliationBatchData rbd "
                    + "where rbd.batch = :batch "
                    + "and rbd.updatedAt is null "
                    + "group by rbd.peerOrgCode")
                    .setParameter("batch", batch);


The peerOrgCode is mapped on ReconciliationBatchData as follows:
Code:
@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "Peer_Org_Code_Id", nullable = false)
    public PeerOrgCode getPeerOrgCode() {
        return peerOrgCode;
    }



Immediately after this we iterate over the query results and try to use the id of the peerOrgCode:
Code:
for (final PeerOrgCodeUpdate update : peerOrgCounts) {
            LOG.debug("processPeerOrgCounts(): update [#0]", update);
            final PeerOrgCode peerOrgCode = update.getPeerOrgCode();
            LOG.debug("processPeerOrgCounts(): peerOrgCode [#0]", peerOrgCode);
            final Long peerOrgCodeId = update.getPeerOrgCode().getId();
            LOG.debug("processPeerOrgCounts(): peerOrgCodeId [#0]", peerOrgCodeId);
            final PeerOrgCode peerOrg = em.find(PeerOrgCode.class, peerOrgCodeId);


The problem is that it appears like something is wrong with the lazy initialisation of the PeerOrgCode:
Code:
2008-06-30 11:16:33,500 DEBUG [com.synyati.spurwing.reconciliation.business.ReconciliationSummaryUtil] processPeerOrgCounts(): update [ReconciliationSummaryUtil.PeerOrgCodeUpdate [PeerOrgCode [AuditableIdentifiableEntity = [3], NTB], 2000]]
2008-06-30 11:16:33,500 DEBUG [com.synyati.spurwing.reconciliation.business.ReconciliationSummaryUtil] processPeerOrgCounts(): peerOrgCode [PeerOrgCode [AuditableIdentifiableEntity = [3], NTB]]
2008-06-30 11:16:33,500 DEBUG [com.synyati.spurwing.reconciliation.business.ReconciliationSummaryUtil] processPeerOrgCounts(): peerOrgCodeId [null]
2008-06-30 11:16:33,500 ERROR [com.synyati.spurwing.base.interceptor.SpurwingExceptionHandler] General exception
java.lang.IllegalArgumentException: id to load is required for loading
   at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:51)
   at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:33)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:812)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
   at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:174)
   at org.jboss.ejb3.entity.TransactionScopedEntityManager.find(TransactionScopedEntityManager.java:171)
   at com.synyati.spurwing.reconciliation.business.ReconciliationSummaryUtil.processPeerOrgCounts(ReconciliationSummaryUtil.java:199)
   at com.synyati.spurwing.reconciliation.upload.ReconciliationBatchUpload.uploadBatchData(ReconciliationBatchUpload.java:299)
   at com.synyati.spurwing.reconciliation.business.ReconciliationServiceBean.uploadBatch(ReconciliationServiceBean.java:96)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
   at com.synyati.spurwing.base.interceptor.SpurwingSecurityInterceptor.securityCheck(SpurwingSecurityInterceptor.java:71)
   at sun.reflect.GeneratedMethodAccessor291.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
   at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
   at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:101)
   at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
   at sun.reflect.GeneratedMethodAccessor290.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
   at com.synyati.spurwing.base.interceptor.SpurwingExceptionHandler.handleException(SpurwingExceptionHandler.java:72)
   at sun.reflect.GeneratedMethodAccessor289.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
   at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
   at org.jboss.aspects.tx.TxInterceptor$RequiresNew.invoke(TxInterceptor.java:262)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:166)
   at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:108)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
   at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
   at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
   at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:81)
   at $Proxy204.uploadBatch(Unknown Source)
   at com.synyati.spurwing.reconciliation.ReconciliationMessageBean.onMessage(ReconciliationMessageBean.java:170)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
   at com.synyati.spurwing.base.interceptor.SpurwingSecurityInterceptor.securityCheck(SpurwingSecurityInterceptor.java:71)
   at sun.reflect.GeneratedMethodAccessor291.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
   at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
   at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
   at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
   at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
   at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:118)
   at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
   at sun.reflect.GeneratedMethodAccessor290.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
   at com.synyati.spurwing.base.interceptor.SpurwingExceptionHandler.handleException(SpurwingExceptionHandler.java:72)
   at sun.reflect.GeneratedMethodAccessor289.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
   at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.aspects.tx.TxPolicy.invokeInNoTx(TxPolicy.java:66)
   at org.jboss.aspects.tx.TxInterceptor$NotSupported.invoke(TxInterceptor.java:112)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
   at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:245)
   at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
   at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
   at $Proxy175.onMessage(Unknown Source)
   at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
   at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:891)
   at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
   at org.jboss.mq.SpySession.run(SpySession.java:323)
   at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:237)
   at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
   at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
   at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
   at java.lang.Thread.run(Unknown Source)


I've attached with a debugger, and can see that the peerOrgCode is actually a lazy initialisation assistant, and the that "handler" in the assistent is initialised with the correct details for the peerOrgCode (which is why toString() appears to work) however whenever I invoke the getters, null is always returned.

Is there some rule I don't know about regarding using "select new" and lazy initialisation?

Here's the detials re our hibernate version:
Code:
2008-06-30 10:38:42,953 INFO  [org.hibernate.ejb.Version] Hibernate EntityManager 3.2.1.GA
2008-06-30 10:38:43,000 INFO  [org.hibernate.cfg.annotations.Version] Hibernate Annotations 3.2.1.GA
2008-06-30 10:38:43,031 INFO  [org.hibernate.cfg.Environment] Hibernate 3.2.5


We're running mysql 5.1.

Please, any help would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 10:39 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I'm not sure if it's even LazyInitialization. I mean, it's telling you it doesn't have an id to load the object. Even with LazyInitializationExceptions the unloaded proxy should know the associated id. Could there be records in the database that don't have ids for some reason?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 06, 2008 6:40 pm 
Newbie

Joined: Thu Jun 26, 2008 12:50 am
Posts: 9
Hi & thanks for you reply.

The Id is definately not null in the DB. It's our primary key in the DLL, and the attribute on our entity is annotated with @Id. One things though, that attribute comes form the PeerOrgCodes' parent class (AuditableIdentifiableEntity) which is marked as @MappedSuperclass.

In the log output you can see the line with
Quote:
[PeerOrgCode [AuditableIdentifiableEntity = [3], NTB]]
in it. This output is from the toString() method on the PeerOrgCode, which is calling super.toString() and the AuditableIdentifiableEntity.toString() is output the id, which in this case is 3.

I've found that I can invoke all the getter & setter and other methods on the PeerOrgCode, and they all return correct values - except getId().

I attached to jBoss with a debugger and found the PeerOrgCode is actually an instance of JavassistLazyInitializer. Inside the JavassistLazyInitializer it appears the target is correctly initialised with our PeerOrgCode object, but for some reason when we invoke getId() on it it's returning null.

Any thoughts or help is appreciated heaps.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 06, 2008 6:43 pm 
Newbie

Joined: Thu Jun 26, 2008 12:50 am
Posts: 9
Oh, and I forgot, the error message occurs where we were trying to do PearOrgCode blah = em.find(PeerOrgCode.class, peerOrgCode.getId()), and since getId() return null, it thinks we're tyrnig to load with a null Id.


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