hi all,
i have a master which has an id of sequence generator and my detail has 3 primary keys, one of those is master id. my mapping are the followings:
my master
Code:
<hibernate-mapping auto-import="true" default-lazy="true">
    <class name="net.nationalpayment.pps.model.IncentiveProgram" table="Incentive">
        <id name="incentiveProgramId" column="Inc_IncProgId" type="long">
            <generator class="sequence"/>
        </id>
        <property name="agencyId" column="Inc_AgencyId" type="string" length="7"/>
        <property name="dealerId" column="Inc_DlrId" type="string" length="20"/>
        <property name="effectiveFrom" column="Inc_EffFrom" type="date"/>
        <property name="effectiveTo" column="Inc_EffTo" type="date"/>
        <property name="allDealerReps" column="Inc_AllDlrReps" type="integer"/>
        <property name="npnCycle1Fee" column="Inc_NPNCycle1Inc" type="double"/>
        <property name="npnCycle2Fee" column="Inc_NPNCycle2Inc" type="double"/>
        <property name="used" column="Inc_IsUsed" type="integer"/>
        <property name="comments" column="Inc_Comm" type="string" length="4000"/>
        <set name="incentiveProgramDetails" cascade="all, delete-orphan" lazy="false">
            <key column="Ind_Id"/>
            <one-to-many class="net.nationalpayment.pps.model.IncentiveProgramDetail"/>
        </set>
        <property name="auditInfo" type="net.nationalpayment.pps.model.AuditInfoUserType">
            <column name="LAST_UPDATED_ON"/>
            <column name="LAST_UPDATED_BY"/>
            <column name="CREATED_DATE"/>
            <column name="CREATED_BY"/>
        </property>
    </class>
</hibernate-mapping>
my detail
Code:
<hibernate-mapping auto-import="true" default-lazy="true">
    <class name="net.nationalpayment.pps.model.IncentiveProgramDetail" table="Incentive_Dtl">
      <composite-id name="incentiveDetailId" class="net.nationalpayment.pps.model.IncentiveProgramDetailId">
         <key-property name="incentiveProgramId" column="Ind_IncProgId" type="long"/>
         <key-property name="entityId" column="Ind_EntityId" type="string" length="30"/>
            <key-property name="entityType" column="Ind_EntityType" type="string" length="2"/>
        </composite-id>
        <property name="cycle1Fee" column="Ind_Cycle1Inc" type="double"/>
        <property name="cycle2Fee" column="Ind_Cycle2Inc" type="double"/>
        <many-to-one name="incentive" class="net.nationalpayment.pps.model.IncentiveProgram"
         column="Ind_Id" lazy="false"/>
        <property name="auditInfo" type="net.nationalpayment.pps.model.AuditInfoUserType">
            <column name="LAST_UPDATED_ON"/>
            <column name="LAST_UPDATED_BY"/>
            <column name="CREATED_DATE"/>
            <column name="CREATED_BY"/>
        </property>
    </class>
</hibernate-mapping>
my class that holds the primary keys
Code:
public class IncentiveProgramDetailId implements java.io.Serializable{
    private Long incentiveProgramId;
    private String entityId;
    private String entityType;
    public String getEntityId() {
        return entityId;
    }
    public void setEntityId(String entityId) {
        this.entityId = entityId;
    }
    public String getEntityType() {
        return entityType;
    }
    public void setEntityType(String entityType) {
        this.entityType = entityType;
    }
    public Long getIncentiveProgramId() {
        return incentiveProgramId;
    }
    public void setIncentiveProgramId(Long incentiveProgramId) {
        this.incentiveProgramId = incentiveProgramId;
    }
    public boolean equals(Object obj){
      if (obj == null ){
         return false;
      }
      if (!(obj instanceof net.nationalpayment.pps.model.IncentiveProgramDetailId))
      {
         return false;
      }
      else{
            net.nationalpayment.pps.model.IncentiveProgramDetailId detailId =
                    (net.nationalpayment.pps.model.IncentiveProgramDetailId) obj;
         if (null == this.getIncentiveProgramId() || null == detailId.getIncentiveProgramId() ||
            null == this.getEntityId() || null == detailId.getEntityId() ||
                null == this.getEntityType()|| null == detailId.getEntityType())
            return false;
         else
            return (this.getIncentiveProgramId().equals(detailId.getIncentiveProgramId()) &&
                   (this.getEntityId().equals(detailId.getEntityId())) &&
                        (this.getEntityType().equals(detailId.getEntityType())));
      }
   }
}
my questions are:
1) when i save the record, does the hibernate will automatically assign the master id to the detail? im confuse since master id is system generated
2) save is working now but i did this in my dao implementation:
Code:
Set details = incentiveProgram.getIncentiveProgramDetails();
        incentiveProgram.setIncentiveProgramDetails(null);
        IncentiveProgram result = (IncentiveProgram) this.getHibernateTemplate().merge(incentiveProgram);
        Iterator detail = details.iterator();
        while(detail.hasNext()){
            IncentiveProgramDetail incentive_detail = (IncentiveProgramDetail) detail.next();
            incentive_detail.getIncentiveDetailId().setIncentiveProgramId(result.getIncentiveProgramId());
            this.storeIncentiveProgramDetail(incentive_detail);
        }
        return this.loadIncentiveProgram(result.getIncentiveProgramId());
is there a better solution to this?
3) when i delete the record(s) only the master will be deleted. i dont know what happen...
any help are greatly appreciated!
regards,
think