-->
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: One-To-One Lazy Loading Problem
PostPosted: Thu Sep 13, 2012 9:37 am 
Newbie

Joined: Tue Nov 11, 2008 9:54 am
Posts: 6
Hello,

I am using Hibernate ORM 4.1.6 with JBoss AS 7.1.1. My project is packaged as an EAR, which has a WAR and an EJB-JAR in it. Also, entities are bytecode enhanced and packaged as a seperate JAR, which resides in the lib directory of the EAR. I have used build time bytecode instrumentation for lazy loading one-to-one and many-to-one associations. One-To-One lazy works fine when the association is not null, but when it is null, I am getting the following exception:

Code:
15:49:53,158 ERROR [org.jboss.ejb3.invocation] (http-0.0.0.0-0.0.0.0-443-1) JBAS014134: EJB Invocation failed on component ProjeTeklifiYoneticisi for method public abstract tr.gov.tubitak.bilgem.bte.g222.kays.varlik.yonetim.basvuruyonetimi.ProjeTeklifi tr.gov.tubitak.bilgem.bte.g222.kays.pfdy.servisarayuzu.yonetim.basvuruyonetimi.IProjeTeklifiYoneticisi.getir(): javax.ejb.EJBTransactionRolledbackException: Transaction rolled back
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleEndTransactionException(CMTTxInterceptor.java:115) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:95) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:232) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
   at tr.gov.tubitak.bilgem.bte.g222.kays.pfdy.servisarayuzu.yonetim.basvuruyonetimi.IProjeTeklifiYoneticisi$$$view2691.getir(Unknown Source) [PfdyServisArayuzu.jar:]
   at tr.gov.tubitak.bilgem.bte.g222.kays.pfdy.istemci.sayfa.yonetim.mdpyonetimi.mdpsecimi.controller.MdpSecController.mdpSec(MdpSecController.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_02]
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_02]
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_02]
   at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_02]
   at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
   at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
   at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
   at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
   at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
   at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
   at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
   at javax.faces.component.UICommand.broadcast(UICommand.java:315)
   at javax.faces.component.UIData.broadcast(UIData.java:1093)
   at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
   at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
   at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
   at tr.gov.tubitak.bilgem.bte.g222.kays.pfdy.istemci.server.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:19)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
   at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
   at tr.gov.tubitak.bilgem.bte.g222.kays.pfdy.istemci.server.giris.SistemeGirisFiltresi.doFilter(SistemeGirisFiltresi.java:220)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489)
   at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
   at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
   at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_02]
Caused by: javax.transaction.RollbackException: ARJUNA016053: Could not commit transaction.
   at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1177)
   at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:117)
   at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
   at org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:92) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   ... 68 more
Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of tr.gov.tubitak.bilgem.bte.g222.kays.varlik.yonetim.basvuruyonetimi.ProjeTeklifiDetay.id
   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377) [hibernate-entitymanager-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300) [hibernate-entitymanager-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1306) [hibernate-entitymanager-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.ejb.AbstractEntityManagerImpl$CallbackExceptionMapperImpl.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1500) [hibernate-entitymanager-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:109) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273)
   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93)
   at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:164)
   at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165)
   ... 71 more
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of tr.gov.tubitak.bilgem.bte.g222.kays.varlik.yonetim.basvuruyonetimi.ProjeTeklifiDetay.id
   at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:62) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:341) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4425) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4147) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:209) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.event.internal.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:495) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:118) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.internal.SessionImpl.firePersistOnFlush(SessionImpl.java:870) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.internal.SessionImpl.persistOnFlush(SessionImpl.java:863) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.engine.spi.CascadingAction$8.cascade(CascadingAction.java:346) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:380) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:323) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:208) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:165) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:160) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:151) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1214) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:403) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:104) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]
   ... 77 more
Caused by: java.lang.NullPointerException
   at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:54) [rt.jar:1.7.0_02]
   at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36) [rt.jar:1.7.0_02]
   at java.lang.reflect.Field.get(Field.java:372) [rt.jar:1.7.0_02]
   at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]


Here are the simplified versions of the two entities that causes the above exception (I have omitted some fields and all getters and setters) :

Code:
@Entity
@Table(name = "PROJE_TEKLIFI", schema = "KAYS")
public class ProjeTeklifi implements IVarlik, Serializable {

   @Id
   @Column(name = "ID")
   @SequenceGenerator(name = "projeTeklifiSequenceGenerator", sequenceName = "S_PROJE_TEKLIFI", allocationSize = 1)
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "projeTeklifiSequenceGenerator")
   private Long id;
   
   @OneToOne( cascade = CascadeType.ALL, orphanRemoval = true, fetch=FetchType.LAZY, optional=true)
   @PrimaryKeyJoinColumn
   @LazyToOne(value = LazyToOneOption.NO_PROXY)
   private ProjeTeklifiDetay projeTeklifiDetay;
   
   @Version
   @Column(name = "VERSIYON")
   private Long versiyon;
}

@Entity
@Table(name="PROJE_TEKLIFI_DETAY",schema="KAYS")
public class ProjeTeklifiDetay  implements java.io.Serializable,IVarlik {

   private static final long serialVersionUID = 8521125823270962422L;
   
   @Id
   @Column(name="ID")
   private Long id;
   
   @OneToOne(mappedBy="projeTeklifiDetay", fetch=FetchType.LAZY, optional=true)
   @MapsId
   @JoinColumn(name="ID")
   @LazyToOne(value = LazyToOneOption.NO_PROXY)
   private ProjeTeklifi projeTeklifi;
   
   @Version
   @Column(name="VERSIYON")
   private Long versiyon;
}


Specifically, when I call getProjeTeklifiDetay on an object of ProjeTeklifi, if the projeTeklifiDetay attribite is not null, it works fine. If it's null, I am getting the above exception.

BTW, I have tried this with the default Hibernate ORM version (hibernate core 4.0.1) that comes with JBoss 7.1.1 and it doesn't work either.


Top
 Profile  
 
 Post subject: Re: One-To-One Lazy Loading Problem
PostPosted: Sat Sep 15, 2012 12:21 am 
Beginner
Beginner

Joined: Fri Sep 14, 2012 10:41 am
Posts: 20
I am no fan on using annotations because it adds another layer of complexity because you have to remember a very complex syntax on top of learning Hibernate. If you have a problem with annotations, it's extreemly difficult to spot visually. However using the XML file metadata is much simpler. There is a consistency in the XML syntax that is not present in the annotation format. Spottting errors is easier in XML.

Coming back to your problem.... Having a null foreign key can cause a problem. Did you declare that the foreign key should be not-null and you are accountering a null foreign key?

In the book, they discourage having null foreign keys. If you association is optional (with null foreigh key), it is recommended to use a join table.

I hope that helps or gives you avenues of investigation.


Top
 Profile  
 
 Post subject: Re: One-To-One Lazy Loading Problem
PostPosted: Mon Sep 17, 2012 4:39 am 
Newbie

Joined: Tue Nov 11, 2008 9:54 am
Posts: 6
I am getting this error on one-to-one relations. I don't think it is suitable to use association tables for one-to-one relations, is it?


Top
 Profile  
 
 Post subject: Re: One-To-One Lazy Loading Problem
PostPosted: Tue Oct 16, 2012 3:42 am 
Newbie

Joined: Tue Nov 11, 2008 9:54 am
Posts: 6
Well, I figured out the problem. When debugging in Eclipse, the binary class files were not bytecode enhanced, so they are not compatible with the class files that are deployed to JBoss. This causes the specified exception.


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.