Component didn't work as I had hoped. I was able to map shippingId column in OrderHeader, but only got the id, (because only the id is in OrderHeader)not all of the attributes of the class (they returned null). I'm wondering if this is something taht needs to be done in the BillTo mapping file? To be more clear of what is happening, I'll provide code:
Order_Overview Table (OrderHeader)
Code:
public class OrderHeader implements java.io.Serializable {
// Fields
private String orderType;
private Long statusId;
private Long orderNumber;
private Long orderGenerated;
private Long billToId;
private Long shipToId;
private Long storeId;
private Long serviceId;
private Set<OrderDetail> orderDetails = new HashSet<OrderDetail>();
private BillTo billToDetails;
// Setters/Getters for Association Mappings
public Set<OrderDetail> getOrderDetails() {
return this.orderDetails;
}
public void setOrderDetails(Set<OrderDetail> orderDetails) {
this.orderDetails = orderDetails;
}
public BillTo getBillToDetails() {
return billToDetails;
}
public void setBillToDetails(BillTo billToDetails) {
this.billToDetails = billToDetails;
}
public String getOrderType() {
return this.orderType;
}
public void setOrderType(String orderType) {
this.orderType = orderType;
}
public Long getStatusId() {
return this.statusId;
}
public void setStatusId(Long statusId) {
this.statusId = statusId;
}
public Long getOrderNumber() {
return this.orderNumber;
}
public void setOrderNumber(Long orderNumber) {
this.orderNumber = orderNumber;
}
public Long getOrderGenerated() {
return this.orderGenerated;
}
public void setOrderGenerated(Long orderGenerated) {
this.orderGenerated = orderGenerated;
}
public Long getBillToId() {
return this.billToId;
}
public void setBillToId(Long billToId) {
this.billToId = billToId;
}
public Long getShipToId() {
return this.shipToId;
}
public void setShipToId(Long shipToId) {
this.shipToId = shipToId;
}
public Long getStoreId() {
return this.storeId;
}
public void setStoreId(Long storeId) {
this.storeId = storeId;
}
public Long getServiceId() {
return this.serviceId;
}
public void setServiceId(Long serviceId) {
this.serviceId = serviceId;
}
public boolean equals(Object other) {
....
}
public int hashCode() {
.....
}
}
BillTo TableCode:
public class BillTo implements java.io.Serializable{
// Fields
private Long billToId;
private String address1;
private String address2;
private String address3;
private String address4;
private String address5;
private String address6;
private String zip;
private String state;
private String country;
private String phone;
private String email;
// Property accessors
public Long getBillToId() {
return billToId;
}
public void setBillToId(Long billToId) {
this.billToId = billToId;
}
public String getAddress1() {
return this.address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return this.address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getAddress3() {
return this.address3;
}
public void setAddress3(String address3) {
this.address3 = address3;
}
public String getAddress4() {
return this.address4;
}
public void setAddress4(String address4) {
this.address4 = address4;
}
public String getAddress5() {
return this.address5;
}
public void setAddress5(String address5) {
this.address5 = address5;
}
public String getAddress6() {
return this.address6;
}
public void setAddress6(String address6) {
this.address6 = address6;
}
public String getZip() {
return this.zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return this.country;
}
public void setCountry(String country) {
this.country = country;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
}
Mapping file - OrderHeader.hbm.xmlCode:
<hibernate-mapping>
<class name="OrderHeader">
<id name="orderNumber" type="java.lang.Long">
<column name="D0DOCO" precision="8" scale="0" />
</id>
<property name="orderType" type="java.lang.String">
<column name="D0DCTO" length="2" />
</property>
<property name="statusId" type="java.lang.Long">
<column name="D0STS" precision="5" scale="0" />
</property>
<property name="orderGenerated" type="java.lang.Long">
<column name="D0TRDJ" precision="6" scale="0" />
</property>
<property name="shipToId" type="java.lang.Long">
<column name="D0SHAN" precision="8" scale="0" />
</property>
<property name="storeId" type="java.lang.Long">
<column name="D0URAB" precision="8" scale="0" />
</property>
<property name="serviceId" type="java.lang.Long">
<column name="D0CMC1" precision="8" scale="0" />
</property>
<set name="orderDetails" inverse="true" lazy="false" cascade="all">
<key column="D5DOCO" />
<one-to-many class="OrderDetail" />
</set>
<component name="billToDetails" class="BillTo" lazy="true">
<property name="billToId" column="D0AN8" />
</component>
</class>
</hibernate-mapping>
Mapping file - BillTo.hbm.xmlCode:
<hibernate-mapping>
<class name="BillTo">
<id name="billToId" type="java.lang.Long">
<column name="D1AN8" precision="8" scale="0" />
</id>
<property name="address1" type="java.lang.String">
<column name="D1ADD1" length="40" />
</property>
<property name="address2" type="java.lang.String">
<column name="D1ADD2" length="40" />
</property>
<property name="address3" type="java.lang.String">
<column name="D1ADD3" length="40" />
</property>
<property name="address4" type="java.lang.String">
<column name="D1ADD4" length="40" />
</property>
<property name="address5" type="java.lang.String">
<column name="D1ADD5" length="40" />
</property>
<property name="address6" type="java.lang.String">
<column name="D1ADD6" length="40" />
</property>
<property name="zip" type="java.lang.String">
<column name="D1ADDZ" length="12" />
</property>
<property name="state" type="java.lang.String">
<column name="D1ADDS" length="3" />
</property>
<property name="country" type="java.lang.String">
<column name="D1CTR" length="3" />
</property>
<property name="phone" type="java.lang.String">
<column name="D1PH1" length="20" />
</property>
<property name="email" type="java.lang.String">
<column name="D1EMAIL" length="40" />
</property>
</class>
</hibernate-mapping>
Really appreciate any insight into how to best retreive a BillTo instance using the billToId in OrderHeader table. Thank you.[/code]