1 2 3 4 5 Previous Next 70 Replies Latest reply on Apr 20, 2006 3:38 PM by clebert.suconic Go to original post
      • 45. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
        phon

        hi
        has anyone been able to solve the bug about passivcation of statefull session beans already (http://jira.jboss.com/jira/browse/EJBTHREE-423) ?

        i now use the new EJB3 RC5 and it seems the bug is still there, but has changed form. where i got a ClassCastException with the previous version i nog get the following exception (being the last in a series of exceptions that are thrown when the server tries to passivate the bean):

        Caused by: java.lang.NullPointerException
         at java.lang.Class.isAssignableFrom(Native Method)
         at org.jboss.serial.classmetamodel.SunConstructorManager.getConstructor(SunConstructorManager.java:64)
         at org.jboss.serial.classmetamodel.ClassMetamodelFactory.findConstructor(ClassMetamodelFactory.java:288)
         at org.jboss.serial.classmetamodel.ClassMetamodelFactory.getClassMetaData(ClassMetamodelFactory.java:257)
         at org.jboss.serial.persister.ClassReferencePersister.writeData(ClassReferencePersister.java:44)
         at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
         at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:266)
         at org.jboss.serial.persister.ArrayPersister.saveObjectArray(ArrayPersister.java:96)
         at org.jboss.serial.persister.ArrayPersister.writeData(ArrayPersister.java:87)
         at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
         at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:266)
         at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:81)
         at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:46)
         at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
         at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:266)
         at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:81)
         at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:46)
         at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
         at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:266)
         at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:81)
         at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:46)
         at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:117)
         at org.jboss.serial.objectmetamodel.DataContainer$DataContainerOutput.writeObject(DataContainer.java:266)
         at org.jboss.serial.persister.ObjectOutputStreamProxy.writeObjectOverride(ObjectOutputStreamProxy.java:45)
         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:287)
         at java.util.HashMap.writeObject(HashMap.java:985)
         ... 61 more
        




        • 46. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
          jwynett

          Alex:

          The error doesn't occur in the finder and the log method you mentioned is never executed. The error occurs when it is sending the data out of the server to the client. All the methods work fine as long as the data is never marshalled out of the server.

          I thought maybe it was a classpath problem on the client however I did everything I could think of the make sure the classpath was ok and found that by changing the relationships to EAGER the problem went away. I made that decision when I realized the HibernateProxy class was involved.

          Another thing I found out recently. The problem with the relationships isn't necessarily in the Device entity itself but somewhere in the network of relationships it is involved in. After making a few relationships EAGER in some other entities that were also causing problems, I found that I could put the relationships back to LAZY in Device without causing the problem to reappear.

          Jon

          • 47. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
            martinganserer

            Hello,

            could you please describe or post the EagerOnDemand class. I would really appreciate that as I am very interested in working with ejb3 on remote clients.

            Thanks a lot!

            • 48. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
              jwynett

              Martin:

              The EagerOnDemand is something I wrote to enable a client to easily and dynamically specify which relationships it needs to load when retrieving entities. Each entity defines a static EntityMapping for each relationship.

              You create an EagerOnDemand instance providing an EntityMapping for the relationships you want to load. Then the EagerOnDemand uses reflection to call the accessor methods for the specified relationships before shipping the entity out to the client.

              So if a client wants to load a User with its Organization and Permissions relationships loaded, it will supply EagerOnDemand.create(User.Organization, User.Permissions) to the finder.

              Jon

              • 49. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                clebert.suconic

                For that NullPointerException, you need to replace jboss-serialization.jar by this one:

                http://labs.jboss.com/portal/index.html?ctrl:id=page.default.downloads&project=serialization


                I have fixed Hibernate Proxy Serialization by creating a mock session and a testcase within Jbossserialization. Is now fixed.

                If you are using CVS, I'm going to upgrade it soon.

                • 50. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                  phon

                   

                  I have fixed Hibernate Proxy Serialization by creating a mock session and a testcase within Jbossserialization. Is not fixed.


                  i'm a little confused :)
                  is there a solution availlable at the moment?

                  • 51. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                    martinganserer

                    Hi Jon,

                    does your EagerOnDemand work with several levels, or is your solution limited on one level only?
                    E. g. you have a user that has several organisations and each organisation has several departments.

                    Regards
                    Martin

                    • 52. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                      phon

                      martin
                      if you're interested in fetch relations dynamically read this article :

                      http://www.javalobby.org/articles/hibernate-query-101/

                      it even has a sample implementation

                      • 53. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                        jwynett

                        Regarding the new jboss-serialization.jar, that seems to also fix my ClassClassException reported earlier in the forum thread.

                        To Martin: My EagerOnDemand class does multi-level relationship loading. So you can load User.Organization and also Organization.Address.

                        The article suggested by Phon is good. Originally I tried using the Fetch Join queries and encountered the problem described in the article where you can't create a distinct query. The problem occurs when you have 1-to-N relationships with many rows and you may load a number of relationships at once. So if I had 10 users each in 10 groups containing 10 permissions, the query would return 1000 rows each repeating the data from every object. The amount of data was huge and took too long to retrieve and process.

                        In those cases I found it faster to load the relationships independently. I actually got this idea by looking at the queries issued by the JBoss server when these relationships were defined as EAGER. There would be a separate query each for Users and Groups and Permissions.

                        • 54. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                          clebert.suconic

                           

                          Quote:
                          I have fixed Hibernate Proxy Serialization by creating a mock session and a testcase within Jbossserialization. Is not fixed .


                          i'm a little confused :)
                          is there a solution availlable at the moment?


                          eh eh.... I fixed my post (as I have admin permissions)

                          I meant "is now fixed"...
                          My brain had a communication problem with my fingers.. sorry :-)

                          • 55. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                            phon

                            hehe, no problem :)
                            and what should i do to fix it, do i have to use the CVS version, or will a new version be released soon ?

                            • 56. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                              jwynett

                              I'm still getting an exception even using the fixed jboss-serialization.jar and I've narrowed it down to a pretty specific case. For me it happens on any ManyToOne that is LAZY and I don't have problems with other types of relationships.

                              Note the error occurs when doing a find by Id however it does not occur in the server code as the find is successful. It occurs when the data is being serialized to the client.

                              To test this I created a test case with two entity beans and one session bean. The stack trace and the full code for the beans is below. The problem is triggered when Device.getIpAddress is set to LAZY and fixed when that same method is set to EAGER.

                              java.lang.reflect.UndeclaredThrowableException
                               at $Proxy0.findDeviceById(Unknown Source)
                               at net.lgsystems.client.LgsClient.main(LgsClient.java:39)
                              Caused by: java.rmi.MarshalException: Failed to communicate. Problem during marshalling/unmarshalling; nested exception is:
                               java.lang.ClassCastException: cannot assign instance of org.hibernate.proxy.SerializableProxy to field net.lgsystems.entity.Device.ipAddress of type net.lgsystems.entity.IpAddress in instance of net.lgsystems.entity.Device
                               at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:287)
                               at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:131)
                               at org.jboss.remoting.Client.invoke(Client.java:258)
                               at org.jboss.remoting.Client.invoke(Client.java:221)
                               at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
                               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                               at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
                               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                               at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
                               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                               at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65)
                               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                               at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
                               ... 2 more
                              Caused by: java.lang.ClassCastException: cannot assign instance of org.hibernate.proxy.SerializableProxy to field net.lgsystems.entity.Device.ipAddress of type net.lgsystems.entity.IpAddress in instance of net.lgsystems.entity.Device
                               at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:1977)
                               at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1157)
                               at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1918)
                               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.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:128)
                               at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:66)
                               at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:260)
                               ... 14 more
                              

                              package net.lgsystems.entity;
                              
                              import javax.persistence.*;
                              import java.io.Serializable;
                              
                              @Entity
                              @Table(name = "device")
                              public class Device implements Serializable {
                              
                               private long id;
                               private String displayName;
                               private IpAddress ipAddress;
                              
                               public Device() {
                               /* default constructor */
                               }
                              
                               public Device(String displayName) {
                               this.displayName = displayName;
                               }
                              
                               /**
                               * Primary Key
                               */
                               @Id
                               @GeneratedValue
                               @Column(name = "device_id")
                               public long getId() {
                               return id;
                               }
                              
                               public void setId(long id) {
                               this.id = id;
                               }
                              
                               @Column(name = "display_name", length = 64, nullable = false)
                               public String getDisplayName() {
                               return displayName;
                               }
                              
                               public void setDisplayName(String displayName) {
                               this.displayName = displayName;
                               }
                              
                               @ManyToOne(fetch = FetchType.LAZY, optional = false)
                               @JoinColumn(nullable = false, name = "ip_address_id")
                               public IpAddress getIpAddress() {
                               return ipAddress;
                               }
                              
                               public void setIpAddress(IpAddress ipAddress) {
                               this.ipAddress = ipAddress;
                               }
                              
                               public boolean equals(final Object o) {
                               if (this == o) {
                               return true;
                               }
                               if (o == null || !(o instanceof Device)) {
                               return false;
                               }
                               Device that = (Device) o;
                               return (this.getId() == that.getId());
                               }
                              
                               public int hashCode() {
                               return (int) this.getId();
                               }
                              
                               public String toString() {
                               return new StringBuilder().append("Device(").append(this.getId()).append("/").append(getDisplayName()).append(")").toString();
                               }
                              }

                              package net.lgsystems.entity;
                              
                              import javax.persistence.*;
                              import java.util.Set;
                              import java.util.HashSet;
                              import java.io.Serializable;
                              
                              @Entity
                              @Table(name = "ip_address")
                              public class IpAddress implements Serializable {
                              
                               private long id;
                               private String myIpAddress;
                               private Set<Device> devices = new HashSet<Device>();
                              
                               public IpAddress() {
                               /* default constructor */
                               }
                              
                               public IpAddress(String ipAddress) {
                               this.myIpAddress = ipAddress;
                               }
                              
                               @Id
                               @GeneratedValue
                               @Column(name = "ip_address_id")
                               public long getId() {
                               return id;
                               }
                              
                               public void setId(long id) {
                               this.id = id;
                               }
                              
                               /**
                               * The actual Ip Address as a String value. This value is persisted and
                               * is used to generate transient numeric representations as needed.
                               *
                               * @return String
                               */
                               @Column(name = "ip_address", nullable = false, length = 15)
                               public String getIpAddress() {
                               return myIpAddress;
                               }
                              
                               public void setIpAddress(String ipAddress) {
                               this.myIpAddress = ipAddress;
                               }
                              
                              
                               @OneToMany(fetch = FetchType.LAZY, mappedBy = "ipAddress")
                               public Set<Device> getDevices() {
                               return devices;
                               }
                              
                               public void setDevices(Set<Device> devices) {
                               this.devices = devices;
                               }
                              
                               public boolean equals(final Object o) {
                               if (this == o) {
                               return true;
                               }
                               if (o == null || !(o instanceof IpAddress)) {
                               return false;
                               }
                               IpAddress that = (IpAddress) o;
                               return (this.getId() == that.getId());
                               }
                              
                               public int hashCode() {
                               return (int) this.getId();
                               }
                              
                               public String toString() {
                               return new StringBuilder().append("IpAddress(").append(this.getId()).append("/").append(this.getIpAddress()).append(")").toString();
                               }
                              }

                              package net.lgsystems.ejb;
                              
                              import net.lgsystems.entity.Device;
                              import net.lgsystems.entity.IpAddress;
                              import org.jboss.annotation.ejb.RemoteBinding;
                              
                              import javax.ejb.Stateless;
                              import javax.ejb.TransactionAttribute;
                              import javax.ejb.TransactionAttributeType;
                              import javax.persistence.EntityManager;
                              import javax.persistence.PersistenceContext;
                              
                              @Stateless
                              @RemoteBinding(jndiBinding = "net.lgsystems.ejb.TestNetworkRemote")
                              public class TestNetworkBean implements TestNetworkRemote {
                               @PersistenceContext(unitName = "lgs")
                               EntityManager entityMgr;
                              
                               @TransactionAttribute(TransactionAttributeType.REQUIRED)
                               public Device findDeviceById(long id) {
                               return entityMgr.find(Device.class, id);
                               }
                              
                               @TransactionAttribute(TransactionAttributeType.REQUIRED)
                               public Device createDeviceView() {
                               try {
                               IpAddress ip = new IpAddress("128.0.0.100");//net);
                               entityMgr.persist(ip);
                              
                               Device d = new Device("Sample Device");
                               d.setIpAddress(ip);
                               entityMgr.persist(d);
                               return d;
                               }
                               catch (Exception e) {
                               e.printStackTrace();
                               return null;
                               }
                               }
                              }


                              This is the main method in the client....
                              public static void main(String[] args) {
                               System.out.println("\nI am running....\n");
                               try {
                               TestNetworkRemote rmt = (TestNetworkRemote) findEJB(TestNetworkRemote.class.getName());
                               Device d = rmt.createDeviceView();
                               System.out.println("Created: " + d);
                               d = rmt.findDeviceById(d.getId());
                               System.out.println("Found: " + d);
                               }
                               catch (Exception e) {
                               e.printStackTrace();
                               }
                               }


                              • 57. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                                phon

                                i think the client side error (related to Hibernate Proxys) hasn't been fixed yet (maybe in CVS by clebert?).
                                the new jboss-serialization.jar fixes the passivation error on stateful session beans also discussed in this topic..

                                • 58. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                                  clebert.suconic

                                  I don't think the error that jwynett is getting is related to jboss-serialization.

                                  The stack trace shows only java serialization.

                                  This is something else. It's a real class cast exception caused by proxies. Maybe you have a classpath issue.

                                  • 59. Re: Problem with Lazy attributes - 4.0.3SP1-EJB3.0RC4
                                    jwynett

                                    I thought maybe it was a classpath issue and played around with it for quite a while without being able to change the behaviour. Below is my classpath in the client build.xml. Perhaps someone might see an obvious problem....

                                     <path id="test.classpath">
                                     <fileset refid="jboss-home"/>
                                     <fileset refid="jboss-server"/>
                                     <path refid="ejb3"/>
                                     <fileset dir="${jboss.home}/lib/endorsed">
                                     <include name="xercesImpl.jar"/>
                                     </fileset>
                                     <path refid="lgs.classpath"/>
                                     </path>
                                    
                                     <fileset id="jboss-home" dir="${jboss.home}/lib">
                                     <include name="jboss-common.jar"/>
                                     <include name="concurrent.jar"/>
                                     <include name="commons-logging.jar"/>
                                     </fileset>
                                    
                                     <fileset id="jboss-server" dir="${jboss.server}/lib">
                                     <include name="jboss-j2ee.jar"/>
                                     <include name="jbosssx.jar"/>
                                     <include name="jboss.jar"/>
                                     <include name="jnpserver.jar"/>
                                     <include name="log4j.jar"/>
                                     <include name="jboss-remoting.jar"/>
                                     <include name="jboss-transaction.jar"/>
                                     <include name="jboss-serialization.jar"/>
                                     </fileset>
                                    
                                     <path id="ejb3">
                                     <fileset id="ejb3-deployer" dir="${jboss.deploy.dir}/ejb3.deployer">
                                     <include name="jboss-ejb3*.jar"/>
                                     <include name="ejb3-persistence.jar"/>
                                     <include name="hibernate3.jar"/>
                                     <include name="jboss-annotations-ejb3.jar"/>
                                     </fileset>
                                     <fileset id="jboss-server-deploy" dir="${jboss.server}/deploy">
                                     <include name="jboss-aop-jdk50.deployer/jboss-aop-jdk50.jar"/>
                                     <include name="jboss-aop-jdk50.deployer/jboss-aspect-library-jdk50.jar"/>
                                     </fileset>
                                     </path>