Hi All,
I have two tables related and I built two hbm files.
The relation between tables are one-to-many.
Everything worked fine but I discovered that I am only getting one record from the many table, and I'm sure that I should be getting more thant one record from the many side.
As you can see I've used a Set with a relation of one-to-many.
Do I have something wrong?
Many Impl Class
Code:
public class SvuRMSCouponInfoImpl extends ListableBusinessObjectImpl implements SvuRMSCouponInfo {
private String couponId;
private String couponBarcode;
private String couponDesc;
private RDate startDate;
private RDate endDate;
private String changeType;
private String changeAmount;
//Locations
private Set<SvuRMSCouponStore> locations = new HashSet<SvuRMSCouponStore>();
//Items
private Set<SvuRMSCouponItem> items;
public void setCouponBarcode(String couponBarcode) {
this.couponBarcode = couponBarcode;
}
public String getCouponBarcode() {
return couponBarcode;
}
public void setCouponDesc(String couponDesc) {
this.couponDesc = couponDesc;
}
public String getCouponDesc() {
return couponDesc;
}
public void setStartDate(RDate startDate) {
this.startDate = startDate;
}
public RDate getStartDate() {
return startDate;
}
public void setEndDate(RDate endDate) {
this.endDate = endDate;
}
public RDate getEndDate() {
return endDate;
}
public void setChangeType(String changeType) {
this.changeType = changeType;
}
public String getChangeType() {
return changeType;
}
public void setChangeAmount(String changeAmount) {
this.changeAmount = changeAmount;
}
public String getChangeAmount() {
return changeAmount;
}
public void setLocations(Collection<SvuRMSCouponStore> locations) {
this.locations.retainAll(locations);
for (SvuRMSCouponStore location : locations) {
addlocation(location);
}
}
private void addlocation(SvuRMSCouponStore location)
{
if (locations.add(location)) {
((SvuRMSCouponStore) location).setSvuRMSCouponInfo(this);
}
}
public Set<SvuRMSCouponStore> getLocations() {
return locations;
}
public void setCouponId(String couponId) {
this.couponId = couponId;
}
public String getCouponId() {
return couponId;
}
}
Main hbm file
Code:
<hibernate-mapping>
<class name="com.supervalu.pricing.rpm.promotions.coupons.bo.SvuRMSCouponInfoImpl" table="POS_COUPON_HEAD">
<composite-id name="objectId" class="com.retek.platform.bo.StringObjectId" access="field" unsaved-value="any">
<key-property name="stringValue" column="COUPON_ID" type="string" access="field" />
</composite-id>
<property name="couponId" column="COUPON_ID" type="string" insert="false" update="false" access="field" />
<property name="couponBarcode" column="COUPON_BARCODE" type="string" insert="false" update="false" access="field" />
<property name="couponDesc" column="COUPON_DESC" type="string" insert="false" update="false" access="field"/>
<property name="startDate" type="com.retek.rpm.domain.calendar.dao.RDateType"><column name="EFFECTIVE_DATE"/></property>
<property name="endDate" type="com.retek.rpm.domain.calendar.dao.RDateType"><column name="EXPIRATION_DATE" /></property>
<property name="changeType" column="PERCENT_IND" type="string" insert="false" update="false" access="field"/>
<property name="changeAmount" column="COUPON_AMT" type="string" insert="false" update="false" access="field"/>
<set name="locations" cascade="all-delete-orphan" lazy="true" inverse="true" access="field" outer-join="false">
<key column="POS_CONFIG_ID" />
<one-to-many class="com.supervalu.pricing.rpm.promotions.coupons.bo.SvuRMSCouponStoreImpl"/>
</set>
</class>
</hibernate-mapping>
Impl class that is called from the first hbm file
Code:
public class SvuRMSCouponStoreImpl extends ListableBusinessObjectImpl implements SvuRMSCouponStore, Serializable {
private int store;
private SvuRMSCouponInfo svuRMSCouponInfo;
public void setStore(int store) {
this.store = store;
}
public int getStore() {
return store;
}
public void setSvuRMSCouponInfo(SvuRMSCouponInfo svuRMSCouponInfo) {
this.svuRMSCouponInfo = svuRMSCouponInfo;
}
public SvuRMSCouponInfo getSvuRMSCouponInfo() {
return svuRMSCouponInfo;
}
}
Hbm file of Impl class that is called from the first hbm file
Code:
<hibernate-mapping>
<class name="com.supervalu.pricing.rpm.promotions.coupons.bo.SvuRMSCouponStoreImpl" table="POS_STORE" dynamic-update="true">
<composite-id name="objectId" class="com.retek.platform.bo.StringObjectId" access="field" unsaved-value="any">
<key-property name="stringValue" column="POS_CONFIG_ID" type="string" access="field" />
</composite-id>
<property name="store" column="STORE" type="integer" insert="false" update="false" access="field" />
</class>
</hibernate-mapping>
Does any one knows what is the problem?
Could any one help?
Many Thanks,
Rui Felix