2

我会尽力提供尽可能多的细节。

我正在使用 Flex(Cairngorm 2)/Java/Hibernate 创建一个 CRM 应用程序。我遇到的基本问题是:

我在 Java 中有一个 Customer 类,它有一个 Address 类的 ArrayList。我在 Flex 中有一个 Customer 类,它有一个 Address 类的 ArrayCollection。

当我为客户进行远程对象调用时,我在 Flex 中返回了一个客户对象,但 ArrayCollecion 对象的数据类型是对象而不是地址。

如果我尝试调用地址类列表,我会得到相同的结果。如果我尝试调用客户类列表,我会在 Flex 中获得客户类列表。

将 tomcat 6 与以下 jar 一起使用:

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

客户身份

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();

    }



}

}

地址.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();

    }



}

}

客户.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();

}

}

地址.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;

}

}

休眠映射: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>

地址.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>
4

1 回答 1

4

Address您应该在 SWF 中的某个地方引用您的课程。最好的方法是在主应用程序中声明一个字段:

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

问题是ArrayCollection在 ActionScript 中没有类型引用(Java 中的泛型)。所以类的字节码不包含在 SWF 中。

于 2011-08-04T15:30:02.227 回答