2

I will try to give as much detail as I can.

I am creating an CRM application using Flex(Cairngorm 2)/Java/Hibernate. The basic problem I am having is this:

I have a Customer class in Java that has an ArrayList of Address classes. I have a Customer class in Flex that has an ArrayCollection of Address classes.

When I make the remote object call for a Customer I get back a Customer object in Flex, but the ArrayCollecion objects have a data type of Object instead of Address.

If I try to call for a List of Address classes I get the same result. If I try to call for a List of Customer classes I get a list of Customer classes in Flex.

Using tomcat 6 with the following jars:

antlr-2.7.6.jar               
flex-messaging-proxy.jar
backport-util-concurrent.jar  
flex-messaging-remoting.jar
cfgatewayadapter.jar          
hibernate3.jar
commons-codec-1.3.jar         
hibernate-jpa-2.0-api-1.0.0.Final.jar
commons-collections-3.1.jar   
javassist-3.12.0.GA.jar
commons-httpclient-3.0.1.jar  
jta-1.1.jar
commons-logging.jar           
logback-classic-0.9.28.jar
concurrent.jar                
logback-core-0.9.28.jar
dom4j-1.6.1.jar               
mybatis-3.0.4.jar
flex-messaging-common.jar     
mysql-connector-java-5.1.16-bin.jar
flex-messaging-core.jar       
slf4j-api-1.6.1.jar
flex-messaging-opt.jar        
xalan.jar

Customer.as

package com.middleburgsalesandservice.gryphon.vo.customer

{


import com.middleburgsalesandservice.gryphon.vo.common.AttributeCollection;



import mx.collections.ArrayCollection;



[Bindable]

[RemoteClass(alias="com.middleburgsalesandservice.gryphon.pojo.customer.Customer")]

public class Customer

{

    public var customerId:int;

    public var startDate:Date = new Date();

    public var endDate:Date = new Date();

    public var createdDate:Date = new Date();

    public var customerFirstName:String;            

    public var customerLastName:String;         

    public var customerUserName:String;     

    public var customerPassWord:String;

    public var addresses:ArrayCollection = new ArrayCollection();

    public var phones:ArrayCollection = new ArrayCollection();

    public var customerOrders:ArrayCollection = new ArrayCollection();

    public var webSites:ArrayCollection = new ArrayCollection();

    public var emails:ArrayCollection = new ArrayCollection();

    public var attributes:ArrayCollection = new ArrayCollection();

    public var attributeCollection:AttributeCollection = new AttributeCollection();



    public function Customer()

    {

        super();

    }



}

}

Address.as

package com.middleburgsalesandservice.gryphon.vo.common

{



[Bindable]

[RemoteClass(alias="com.middleburgsalesandservice.gryphon.pojo.common.Address")]

public class Address 

{

    public var addressId:int;

    public var address1:String;

    public var address2:String; 

    public var city:String;

    public var state:State = new State();

    public var zipCode:String;

    public var addressType:AddressType = new AddressType();

    public var country:Country = new Country();

    public var primaryNumber:int;

    public var primaryAddress:Boolean;

    public var startDate:Date;

    public var endDate:Date;



    public function Address()

    {

        super();

    }



}

}

Customer.java

package com.middleburgsalesandservice.gryphon.pojo.customer;



 import java.util.ArrayList;

 import java.util.Date;

 import java.util.HashSet;

 import java.util.List;

 import java.util.Set;



 import com.middleburgsalesandservice.gryphon.pojo.common.Address;

 import com.middleburgsalesandservice.gryphon.pojo.common.Attribute;

 import com.middleburgsalesandservice.gryphon.pojo.common.AttributeCollection;

 import com.middleburgsalesandservice.gryphon.pojo.common.EmailAddress;

 import com.middleburgsalesandservice.gryphon.pojo.common.Phone;

 import com.middleburgsalesandservice.gryphon.pojo.common.WebAddress;

 import com.middleburgsalesandservice.gryphon.pojo.order.Order;




 public class Customer {

private int customerId;

private Date startDate;

private Date endDate;

private String customerFirstName;           

private String customerLastName;            

private Date createdDate;

private String customerUserName;        

private String customerPassWord;

private List<Address> addresses = new ArrayList<Address>();

private List<Phone> phones = new ArrayList<Phone>();

private List<Order> customerOrders = new ArrayList<Order>();

private List<WebAddress> webSites = new ArrayList<WebAddress>();

private List<EmailAddress> emails = new ArrayList<EmailAddress>();

private List<Attribute> attributes = new ArrayList<Attribute>();

private AttributeCollection attributeCollection;

public String getCustomerFirstName() {

    return customerFirstName;

}

public void setCustomerFirstName(String customerFirstName) {

    this.customerFirstName = customerFirstName;

}

public String getCustomerLastName() {

    return customerLastName;

}

public void setCustomerLastName(String customerLastName) {

    this.customerLastName = customerLastName;

}

public String getCustomerUserName() {

    return customerUserName;

}

public void setCustomerUserName(String customerUserName) {

    this.customerUserName = customerUserName;

}

public String getCustomerPassWord() {

    return customerPassWord;

}

public void setCustomerPassWord(String customerPassWord) {

    this.customerPassWord = customerPassWord;

}

public List<Address> getAddresses() {

    return addresses;

}

public void setAddresses(List<Address> addresses) {

    this.addresses = addresses;

}

public List<Phone> getPhones() {

    return phones;

}

public void setPhones(List<Phone> phones) {

    this.phones = phones;

}

public String getFullName(){

    return this.getCustomerFirstName() + " " + this.getCustomerLastName();

}

/**

 * @return the createdDate

 */

public Date getCreatedDate() {

    return createdDate;

}

/**

 * @param createdDate the createdDate to set

 */

public void setCreatedDate(Date createdDate) {

    this.createdDate = createdDate;

}

/**

 * @return the customerOrders

 */

public List<Order> getCustomerOrders() {

    return customerOrders;

}

/**

 * @param customerOrders the customerOrders to set

 */

public void setCustomerOrders(List<Order> customerOrders) {

    this.customerOrders = customerOrders;

}

/**

 * @return the webSites

 */

public List<WebAddress> getWebSites() {

    return webSites;

}

/**

 * @param webSites the webSites to set

 */

public void setWebSites(List<WebAddress> webSites) {

    this.webSites = webSites;

}

/**

 * @return the emails

 */

public List<EmailAddress> getEmails() {

    return emails;

}

/**

 * @param emails the emails to set

 */

public void setEmails(List<EmailAddress> emails) {

    this.emails = emails;

}

/**

 * @return the attributeCollection

 */

public AttributeCollection getAttributeCollection() {

    return attributeCollection;

}

/**

 * @param attributeCollection the attributeCollection to set

 */

public void setAttributeCollection(AttributeCollection attributeCollection) {

    this.attributeCollection = attributeCollection;

}

/**

 * @return the attributes

 */

public List<Attribute> getAttributes() {

    return attributes;

}

/**

 * @param attributes the attributes to set

 */

public void setAttributes(List<Attribute> attributes) {

    this.attributes = attributes;

}

/**

 * @return the customerId

 */

public int getCustomerId() {

    return customerId;

}

/**

 * @param customerId the customerId to set

 */

public void setCustomerId(int customerId) {

    this.customerId = customerId;

}

/**

 * @return the startDate

 */

public Date getStartDate() {

    return startDate;

}

/**

 * @param startDate the startDate to set

 */

public void setStartDate(Date startDate) {

    this.startDate = startDate;

}

/**

 * @return the endDate

 */

public Date getEndDate() {

    return endDate;

}

/**

 * @param endDate the endDate to set

 */

public void setEndDate(Date endDate) {

    this.endDate = endDate;

}

/* (non-Javadoc)

 * @see java.lang.Object#toString()

 */

@Override

public String toString() {

    return "ID=" + this.getCustomerId() + "|FirstName=" + this.getCustomerFirstName() + "|LastName=" + this.getCustomerLastName();

}

}

Address.java

 package com.middleburgsalesandservice.gryphon.pojo.common;



import java.util.Date;





public class Address {

private int addressId;

private Date startDate;

private Date endDate;

private String address1;

private String address2; 

private String city;

private State state;

private String zipCode;

private AddressType addressType;

private Country country;

private boolean primaryAddress;

public Country getCountry() {

    return country;

}

public void setCountry(Country country) {

    this.country = country;

}

public AddressType getAddressType() {

    return addressType;

}

public void setAddressType(AddressType addressType) {

    this.addressType = addressType;

}

public String getAddress1() {

    return address1;

}

public void setAddress1(String address1) {

    this.address1 = address1;

}

public String getAddress2() {

    return address2;

}

public void setAddress2(String address2) {

    this.address2 = address2;

}

public String getCity() {

    return city;

}

public void setCity(String city) {

    this.city = city;

}

public State getState() {

    return state;

}

public void setState(State state) {

    this.state = state;

}

public String getZipCode() {

    return zipCode;

}

public void setZipCode(String zipCode) {

    this.zipCode = zipCode;

}

/**

 * @return the primaryAddress

 */

public boolean isPrimaryAddress() {

    return primaryAddress;

}

/**

 * @param primaryAddress the primaryAddress to set

 */

public void setPrimaryAddress(boolean primaryAddress) {

    this.primaryAddress = primaryAddress;

}

/**

 * @return the addressId

 */

public int getAddressId() {

    return addressId;

}

/**

 * @param addressId the addressId to set

 */

public void setAddressId(int addressId) {

    this.addressId = addressId;

}

/**

 * @return the endDate

 */

public Date getEndDate() {

    return endDate;

}

/**

 * @param endDate the endDate to set

 */

public void setEndDate(Date endDate) {

    this.endDate = endDate;

}

/**

 * @return the startDate

 */

public Date getStartDate() {

    return startDate;

}

/**

 * @param startDate the startDate to set

 */

public void setStartDate(Date startDate) {

    this.startDate = startDate;

}

}

Hibernate mappings: Customer.hbm.xml

  <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE hibernate-mapping PUBLIC

        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping>

    <class name="com.middleburgsalesandservice.gryphon.pojo.customer.Customer" table="customer">

        <id column="customer_id" name="customerId" type="int">

            <generator class="native"/>

        </id>

        <property column="cust_f_name" name="customerFirstName" />

        <property column="cust_l_name" name="customerLastName" />

        <property column="cust_user_name" name="customerUserName" />

        <property column="cust_pass_word" name="customerPassWord" />

        <property column="startdate" name="startDate" type="java.util.Date"/>

        <property column="enddate" name="endDate" type="java.util.Date"/>

        <property column="created_dt" name="createdDate" type="java.util.Date"/>

        <many-to-one column="attribute_col_id" name="attributeCollection" class="com.middleburgsalesandservice.gryphon.pojo.common.AttributeCollection"/>

        <bag name="addresses" table="cust_address" lazy="false">

            <key column="customer_id"/>

            <many-to-many column="address_id" class="com.middleburgsalesandservice.gryphon.pojo.common.Address"/>

        </bag>

        <bag name="phones" table="cust_phone" lazy="false">

            <key column="customer_id"/>

            <many-to-many column="phone_id" class="com.middleburgsalesandservice.gryphon.pojo.common.Phone"/>

        </bag>

        <bag name="webSites" table="cust_web_address" lazy="false">

            <key column="customer_id"/>

            <many-to-many column="web_address_id" class="com.middleburgsalesandservice.gryphon.pojo.common.WebAddress"/>

        </bag>

        <bag name="emails" table="cust_email" lazy="false">

            <key column="customer_id"/>

            <many-to-many column="email_id" class="com.middleburgsalesandservice.gryphon.pojo.common.EmailAddress"/>

        </bag>

        <bag name="attributes" table="cust_attributes" lazy="false">

            <key column="customer_id"/>

            <many-to-many column="attribute_id" class="com.middleburgsalesandservice.gryphon.pojo.common.Attribute"/>

        </bag>

        <bag name="customerOrders" table="customer_orders" lazy="false">

            <key column="customer_id"/>

            <many-to-many column="order_id" class="com.middleburgsalesandservice.gryphon.pojo.order.Order"/>

        </bag>

     </class>

   </hibernate-mapping>

Address.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="com.middleburgsalesandservice.gryphon.pojo.common.Address" table="address">
        <id column="address_id" name="addressId" type="int">
            <generator class="native"/>
        </id>
        <property column="startdate" name="startDate" type="java.util.Date"/>
        <property column="enddate" name="endDate" type="java.util.Date"/>
        <property column ="addr1" name="address1" />
        <property column ="addr2" name="address2" />
        <property column="city" name="city" />
        <property column="zip_code" name="zipCode" />
        <many-to-one column="state_id" name="state" class="com.middleburgsalesandservice.gryphon.pojo.common.State" />      
        <many-to-one column="address_type_id" name="addressType" class="com.middleburgsalesandservice.gryphon.pojo.common.AddressType" />
        <many-to-one column="country_id" name="country" class="com.middleburgsalesandservice.gryphon.pojo.common.Country" />
        <property column="primary_address" name="primaryAddress" type="java.lang.Boolean" />
  </class>
  </hibernate-mapping>
John
  • 763
  • 1
  • 10
  • 21
  • Tried both ways with no joy. I know that I have it the right place as I have to do something similar when I dynamically create a view. Those are getting compiled in so I have `public var newCustWin:CustomerForm; public var findCustWin:FindCustomer; public var test:TestView; //Tried this public var references:Object = {addressClass:Address}; //And this together and separately public var address:Address;' – John Aug 04 '11 at 15:59

1 Answers1

4

You should refer your Address class somewhere in SWF. The best way to do it is to declare a field in main application:

private var references:Object = {addressClass:Address, someOtheClass:SomeOtherClass};

The problem is that ArrayCollection in ActionScript hasn't type reference (generics in Java). So class' bytecode isn't included in SWF.

Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • Constantiner has it right, we usually just do this in an on initialize method in main. Another place where this will get you, is even if you have the Object referenced in code somewhere, but your using modules, the object wont get compiled into the application and will come over as ASObjects. The same remedy applies. – SuperSaiyen Aug 04 '11 at 15:39
  • If I understand this correctly I need to reference the class so that it is included at compile time. Can I reference it with: public var address:Address; or do I need to do it as above. Will both work? – John Aug 04 '11 at 15:50
  • Guess I should put this here: Tried both ways with no joy. I know that I have it the right place as I have to do something similar when I dynamically create a view. Those are getting compiled in so I have `public var newCustWin:CustomerForm; public var findCustWin:FindCustomer; public var test:TestView; //Tried this public var references:Object = {addressClass:Address}; //And this together and separately public var address:Address;' – John Aug 04 '11 at 16:08
  • You can use [Charles](http://www.charlesproxy.com/) to see your real AMF data. It shows class mappings. If data transfers right you should dig dipper on a client side. In other case the problem is on the server side. – Constantiner Aug 04 '11 at 16:15
  • I have a Flex dump utility that I can dump the object and see what everything about the object and I was looking in the wrong place. Your solution works wonderfully. Thank you. – John Aug 04 '11 at 16:18