2 Replies Latest reply on Mar 13, 2009 4:44 AM by Emil Huseynli

    ManyToOne lazy initialization

    maxxplorer Newbie

      Hi

      I've been struggling with this problem a couple of days and still haven't been able to find any solutions. It's about two simple entities that have a ManyToOne relationship. The following exception is thrown when the owning entity is looked up:

      java.lang.NoClassDefFoundError: Lorg/hibernate/type/AbstractComponentType;
       at java.lang.Class.getDeclaredFields0(Native Method)
       at java.lang.Class.privateGetDeclaredFields(Class.java:2259)
       at java.lang.Class.getDeclaredField(Class.java:1852)
       at java.io.ObjectStreamClass.getDeclaredSUID(ObjectStreamClass.java:1582)
       at java.io.ObjectStreamClass.access$700(ObjectStreamClass.java:52)
       at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:408)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:400)
       at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:297)
       at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:531)
       at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1552)
       at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1908)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1832)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1719)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
       at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:122)
       at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1755)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1717)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1908)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1832)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1719)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
       at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObjectVersion2_2(JavaSerializationManager.java:239)
       at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:133)
       at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:120)
       at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedRead(MicroSocketClientInvoker.java:957)
       at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:586)
       at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:122)
       at org.jboss.remoting.Client.invoke(Client.java:1634)
       at org.jboss.remoting.Client.invoke(Client.java:548)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:67)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107)
       at $Proxy13.get(Unknown Source)
       at com.lab.service.LabTest.testGetAnimal(LabTest.java:55)
      


      Here are the entities involved:


      @Entity
      @Table(name = "ANIMAL")
      public class Animal implements Serializable {
       private long id;
      
       private Farm farm;
      
       @Id
       @GeneratedValue(strategy = GenerationType.IDENTITY)
       @Column(name = "ID")
       public long getId() {
       return id;
       }
      
       public void setId(long id) {
       this.id = id;
       }
      
       @ManyToOne(fetch = FetchType.LAZY)
       @JoinColumn(name="FARM_ID")
       public Farm getFarm() {
       return farm;
       }
      
       public void setFarm(Farm farm) {
       this.farm = farm;
       }
      }
      


      @Entity
      @Table(name = "FARM")
      public class Farm implements Serializable {
       private long id;
      
       @Id
       @GeneratedValue(strategy = GenerationType.IDENTITY)
       @Column(name = "ID")
       public long getId() {
       return id;
       }
      
       public void setId(long id) {
       this.id = id;
       }
      }
      


      An the test case simply looks up the entity through EntityManager:
       @PersistenceContext
       protected EntityManager em;
      
       public <T> T get(Class<T> klass, long id) {
       return em.find(klass, id);
       }
      


      The strangest thing is that there are very few people ran into this problem. For what it's worth, the correct lookup query - considering being lazy - comes up in the hibernate logs:
      select animal0_.ID as ID75_0_, animal0_.FARM_ID as FARM2_75_0_ from ANIMAL animal0_ where animal0_.ID=?
      


      I appreciate any ideas on this.