2 Replies Latest reply on Sep 19, 2009 11:00 PM by Derrick LIN

    Problems when remote calling SFSB wrapped EntityHome

    Derrick LIN Newbie

      Hi, I have few problems when using client to access the EntityHome that is wrapped within a SFSB. Here is the code

      public interface UserManager {
           public void setId(Object Id);
           public Object getId();
           public void setInstance(User instance);
           public User getInstance();
           public boolean isManaged();

      public class UserHome extends EntityHome<User> implements UserManager
          private static final long serialVersionUID = 415824630373139993L;
          @RequestParameter Long userId;
          public Object getId()
              if (userId == null) { return super.getId(); }
              else { return userId; }
          @Override @Begin
          public void create() {
          /* This solves my 1st problem */
          public User getInstance() {
               return super.getInstance();
          public void destory() {}

      public class User implements Serializable
          private static final long serialVersionUID = 5412666781502570678L;
          @Id @GeneratedValue
          private String id;
          private Date birthDate;
           @OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="patient")
          private List<MeasurementData> measurementData = new ArrayList<MeasurementData>();

      My first problem is, after my client obtains the EntityHome by using JNDI look up, and try to get a user by using getInstance(), it throws ClassCastException java.lang.String. I think User's ID is where causes the exception. I somehow fix this by adding an Override getInstance() method in EntityHome. Now it works, but it will be nice if someone can provide an explanation. :)

      My second problem is LazyInitializationException when try to fetching a list of measurement data that belongs to a user. I have read it in other posts and kind of know the cause, but not sure the correct way to fix it. Any help would be appreciated.

      org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.unsw.bsl.dss.user.User.measurementData, no session or session was closed
           at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
           at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
           at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:119)
           at org.hibernate.collection.PersistentBag.size(PersistentBag.java:248)
           at DomainTest.testReadUser(DomainTest.java:77)
           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:592)
           at junit.framework.TestCase.runTest(TestCase.java:164)
           at junit.framework.TestCase.runBare(TestCase.java:130)
           at junit.framework.TestResult$1.protect(TestResult.java:106)
           at junit.framework.TestResult.runProtected(TestResult.java:124)
           at junit.framework.TestResult.run(TestResult.java:109)
           at junit.framework.TestCase.run(TestCase.java:120)
           at junit.framework.TestSuite.runTest(TestSuite.java:230)
           at junit.framework.TestSuite.run(TestSuite.java:225)
           at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
           at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

        • 1. Re: Problems when remote calling SFSB wrapped EntityHome
          Georges Goebel Newbie


          You try to access a one-to-many relation on a detached object (correct me if I am wrong). Yous SFSB loads the entity bean and passes the object (through your remote interface) to your client.

          Why do you use the remote interface ? Only for junit testing ? If so check out the chapter 37 in the seam doc (http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html/testing.html) (The SeamTest class)

          Otherwise there are some ways to fix your lazy loading exception:

          You can fix it by changing the fetch type to EAGER


          Your client can send is object (User) to the SFSB and use it to retrieve the List.

          public List<MeasureItems> getItems (User user) {
              return user.getMesaureItems();


          • 2. Re: Problems when remote calling SFSB wrapped EntityHome
            Derrick LIN Newbie

            Thanks Georges,

            You try to access a one-to-many relation on a detached object (correct me if I am wrong).

            From what I read from Seam in Action, this seems to be the case. I am very new to EJB, so not sure how remote/local calls affect a session bean's life cycle.

            My guess is when a client accesses SFSB by remote, the state is not maintained. So container just passes the reference of object to the client and disposes the SFSB. Does it also mean the Seam-managed PC has no effect when using remote call??

            At the moment, I have to use EAGER fetch type.

            I have to use remote call at this stage as they are separated projects.