These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate not returning roght result
PostPosted: Wed Oct 01, 2008 6:46 pm 
Newbie

Joined: Wed Oct 01, 2008 6:39 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: The Same problem
PostPosted: Thu Oct 02, 2008 12:44 pm 
Newbie

Joined: Thu Oct 02, 2008 12:42 pm
Posts: 1
Hi,

I'm with the same problem, if you have the solutions, please, tell me how


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2008 4:52 pm 
Newbie

Joined: Wed Oct 01, 2008 6:39 pm
Posts: 2
Got the problem fixed.

Just needed to specify the table's primary key correctly. My primary key was three attributes and I only had one specified on hibernate.

Many Thanks,
Regards,
Rui Felix


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.