3 Replies Latest reply on Sep 5, 2006 2:40 PM by Flex_Architect

    Collection Based Property Problem

    Flex_Architect
      Hello All,

      I have what seems to be a simple object domain of User objects that contain multiple PhoneNumber objects. My AS and Java User classes look like this:

      package com.abc.domain
      {
      import mx.collections.ArrayCollection;

      [Managed]
      [RemoteClass(alias="com.abc.domain.User")]

      public class User
      {

      public var id:Number = 0;

      public var firstName:String;

      public var username:String;

      public var lastName:String;

      public var email:String;

      public var phoneNumbers:ArrayCollection;

      public function User():void
      {
      phoneNumbers = new ArrayCollection();
      }

      }
      }

      The corresponding Java Class (using EJB 3.0's Java Persistence API):

      package com.abc.domain;

      import java.io.Serializable;
      import javax.persistence.*;
      import java.util.*;
      import javax.persistence.OneToMany;
      import javax.persistence.CascadeType;
      import javax.persistence.FetchType;
      import javax.persistence.JoinTable;
      import javax.persistence.JoinColumn;
      import javax.persistence.GeneratedValue;

      @Entity
      @Table(name="users")
      public class User implements Serializable {
      private static final long serialVersionUID = -2598982624653333910L;

      @Id
      @GeneratedValue
      private long id;

      @Column(name="first_name")
      private String firstName;

      private String username;

      @Column(name="last_name")
      private String lastName;

      private String email;

      @OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
      @JoinTable(name="user_phone_numbers", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "phone_id", referencedColumnName = "id"))
      private Collection<PhoneNumber> phoneNumbers;

      public User() {
      super();
      }

      *********** Getters and Setters Here ***********
      }

      The PhoneNumber classes are similar in nature.

      The problem I am having is that when I commit() from the DataService object in flex the collection of PhoneNumbers does not appear to be initialized by the class loader. I know that the ArrayCollection exists right up to the point of commiting, but after the updated data returns it is empty. Debugging the server side SessionBean shows the user data intact, with an empty ArrayList for the PhoneNumbers. Am I missing something here? Can you use a Collection of strongly typed objects as a property from FDS to a Java assembler?

      Thanks for the help,
      Anthony McClure
        • 1. Re: Collection Based Property Problem
          aBill
          Hi,

          Try remove
          phoneNumbers = new ArrayCollection();
          from you constructor!
          I saw similar problem before! Hope it helps!

          William Chan
          • 2. Re: Collection Based Property Problem
            Flex_Architect Level 1
            Well tried to remove the Constuctors ArrayCollection instantiation but it does not seem to help. I have to create the instance before adding the PhoneNumber instance to it anyway as I am creating a new user and not updating an existing one.

            I should be able to create a new User instance... instantiate the phoneNumbers array collection... add an instance of a PhoneNumber to the array collection and then commit() correct? Will data services not work with a collection of embedded objects?
            • 3. Re: Collection Based Property Problem
              Flex_Architect Level 1
              I found what I was doing wrong.

              Here is the code I had in the Java class:
              public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) {
              this.phoneNumbers = phoneNumbers;
              }

              It should have been:
              public void setPhoneNumbers( Collection<PhoneNumber> phoneNumbers) {
              this.phoneNumbers = phoneNumbers;
              }

              As this is the datatype set for the private property.