1 Reply Latest reply on Oct 28, 2005 4:52 PM by Emmanuel Bernard

    SCHWERWIEGEND: CGLIB Enhancement failed: Whats that?

    Martin Heinemann Newbie

      Hi,
      im playing around again with EJB3.0. I want to use LAZY fetching and transfer the object to a remote client, no jsp/servlet!, and while testing my application i got this bogus exception.

      First my entity:

      @Entity
      @Table(name="musiccd")
      public class MusicCD implements Serializable{
      
       private int musicCdId;
      
       private String ean;
       private String title;
       private int artistId;
       private Artist artist;
       private String type;
       private float price;
      
       /** Primary key. */
       @Id(generate = GeneratorType.AUTO)
       @Column(name = "musiccd_id")
       public int getMusicCdId() {
       return musicCdId;
       }
       /**
       * Set the primary key.
       */
       public void setMusicCdId(int musicCdId) {
       this.musicCdId = musicCdId;
       }
      
       @Column(name = "ean")
       public String getEan() {
       return ean;
       }
       public void setEan(String ean) {
       this.ean = ean;
       }
      
       // Get Artist
      
       @Column(name = "artist_id", insertable=false, updatable=false)
       public int getArtistId() {
       return artistId;
       }
       public void setArtistId(int artistId) {
       this.artistId = artistId;
       }
      
       @javax.persistence.ManyToOne(fetch = FetchType.LAZY)
       @javax.persistence.JoinColumn(name = "artist_id")
       public Artist getArtist() {
       return artist;
       }
       public void setArtist(Artist artist) {
       this.artist = artist;
       }
      
      ....
      }
      
      
      

      The Artist Entity


      @Entity
      @Table(name="artist")
      public class Artist implements Serializable{
      
       private int artistId;
       private String name;
       private String age;
      
       public Artist() {
       }
      
       /** Primary key. */
       @Id(generate = GeneratorType.AUTO)
       @Column(name = "artist_id")
       public int getArtistId() {
       return artistId;
       }
       public void setArtistId(int artistId) {
       this.artistId = artistId;
       }
      
       @Column(name = "age")
       public String getAge() {
       return age;
       }
       public void setAge(String age) {
       this.age = age;
       }
      
       @Column(name = "name")
       public String getName() {
       return name;
       }
       public void setName(String name) {
       this.name = name;
       }
      
      }
      


      Persisting objects to the database works fine.
      But reading objects from the database throws the following Exception:

      
      28.10.2005 16:46:44 org.hibernate.proxy.CGLIBLazyInitializer getProxy
      SCHWERWIEGEND: CGLIB Enhancement failed: musicstorefull.entity.Artist
      java.lang.NoClassDefFoundError: org/objectweb/asm/Type
       at net.sf.cglib.core.TypeUtils.parseType(TypeUtils.java:180)
       at net.sf.cglib.core.KeyFactory.<clinit>(KeyFactory.java:66)
       at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
       at org.hibernate.proxy.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:45)
       at org.hibernate.proxy.SerializableProxy.readResolve(SerializableProxy.java:55)
       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 java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1006)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1722)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
       at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:107)
       at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1753)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1711)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
       at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:73)
       at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:242)
       at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:112)
       at org.jboss.remoting.Client.invoke(Client.java:226)
       at org.jboss.remoting.Client.invoke(Client.java:189)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:41)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:40)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:41)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:88)
       at $Proxy0.getCD(Unknown Source)
       at musicstorefull.clients.MusicStoreClient2.createNewCDs(MusicStoreClient2.java:55)
       at musicstorefull.clients.MusicStoreClient2.main(MusicStoreClient2.java:75)
      Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
       at $Proxy0.getCD(Unknown Source)
       at musicstorefull.clients.MusicStoreClient2.createNewCDs(MusicStoreClient2.java:55)
       at musicstorefull.clients.MusicStoreClient2.main(MusicStoreClient2.java:75)
      Caused by: java.rmi.ConnectException: Failed to communicate. Problem during marshalling/unmarshalling; nested exception is:
       org.hibernate.HibernateException: CGLIB Enhancement failed: musicstorefull.entity.Artist
       at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:264)
       at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:112)
       at org.jboss.remoting.Client.invoke(Client.java:226)
       at org.jboss.remoting.Client.invoke(Client.java:189)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:41)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:40)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:41)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:88)
       ... 3 more
      Caused by: org.hibernate.HibernateException: CGLIB Enhancement failed: musicstorefull.entity.Artist
       at org.hibernate.proxy.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:53)
       at org.hibernate.proxy.SerializableProxy.readResolve(SerializableProxy.java:55)
       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 java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1006)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1722)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
       at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:107)
       at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1753)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1711)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
       at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:73)
       at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:242)
       ... 15 more
      Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/Type
       at net.sf.cglib.core.TypeUtils.parseType(TypeUtils.java:180)
       at net.sf.cglib.core.KeyFactory.<clinit>(KeyFactory.java:66)
       at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
       at org.hibernate.proxy.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:45)
       ... 39 more
      


      I found something about this issue on the hibernate websites. They say top solve this Problem, i have to write a standard constructor which is at least protected. So i did. But no changes.
      I also got the newest cglib jar (2.1.3) in my classpath for the client.

      When i left out (fetch=FetchType:LAZY) in the ManyToOne annotation on top of getArtist() everything is fine, except the lazy fetching is not working.
      Or does lazy fetching only work with ManyToOne and ManyToMany relations?

      Any ideas?
      Thanks and nice weekend

      Martin