1 Reply Latest reply on Jun 7, 2010 2:47 AM by snkd

    Client side lazy loading & BlazeDS

    jovox

      Hi

      I'm trying to get lazy loading working with a Flex->BlazeDS->EJB3Factory->Seam->EJB3 configuration.

      Everything seem to work quite good now.. Ie, I can load an entity bean (which had @OneToMany relation to another entity) to my flex-client.

       

      This this the code I'm currently using:

       

      package {
      import mx.collections.ArrayCollection;

       

      [Bindable]
      [RemoteClass(alias="com.jovox.ejb.Person")]
      public class Person {
          public var id:int;
          public var name:String;
          public var cars:ArrayCollection;

       

          public function Person() {
          }
      }

       

       

      Entity
      @Name("Car")
      public class Car implements Serializable {
          private int id;
          private String name;
          private Person person;

       

          @Id
          @GeneratedValue(strategy = GenerationType.AUTO)
          public int getId() {
              return id;
          }

       

          public void setId(int id) {
              this.id = id;
          }

       

          public String getName() {
              return name;
          }

       

          public void setName(String name) {
              this.name = name;
          }

       

          @ManyToOne
          @JoinColumn(name="person_id")
          public Person getPerson() {
              return person;
          }

       

          public void setPerson(Person person) {
              this.person = person;
          }
      }

       

      @Entity
      @Name("Person")
      public class Person implements Serializable {
          private int id;
          private String name;
          private List<Car> cars;

       

          @Id
          @GeneratedValue(strategy = GenerationType.AUTO)
          public int getId() {
              return id;
          }

       

          public void setId(int id) {
              this.id = id;
          }

       

          public String getName() {
              return name;
          }

       

          public void setName(String name) {
              this.name = name;
          }

       

          @OneToMany(mappedBy = "person")
          public List<Car> getCars() {
              return cars;
          }

       

          public void setCars(List<Car> cars) {
              this.cars = cars;
          }
      }

       

      @Stateless
      @Name("PersonManager")
      public class PersonManagerBean implements PersonManager {  
          @In
          protected EntityManager entityManager;

       

          public Person getPerson(int id) {
              return entityManager.find(Person.class, id);
          }

       

          public Person savePerson(Person p) {
              return entityManager.merge(p);
          }

      }

       

       

      What happends when I call the remoteobject's (which is my SLSB PersonManagerBean) .getPerson(id) method is that my Person object is successfully serialized to the Flex client. The problem is that the person's Cars are also serialized which is not exactly lazy loading in a client perspective.

       

      I have seen lots of posts where people suggests dpHibernate but I havn't found much documentation about it.

      Does dpHibernate support my configuration? ie, does it work with JPA or do I need to load/persist my entity beans directly using Hibernate?

       

      When I googled for lazy loading, BlazeDS and Flex I read that Seam would solv the lazy loading problems but if I understand it correctly all that is solved is the lazy loading problem between the ejb and the webapp. Not between the webapp and the flex client?

       

      /jonathan

        • 1. Re: Client side lazy loading & BlazeDS
          snkd Level 1

          My self also have the  problem regarding JPA lazy loading is not working under SBI(Spring BlazeDS Integration).So is there a patch or solution for that? JPA(Java Persistance API ) is most popular framwork for ORM.I cannt ignore it.There should be a solution for this bug...Anybody have an idea?