hibernate all-delete-orphan

  (1)
<?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.gdcn.gpms.pms.GDTEC.scgl.model.ForeignAccountsApprove" table="gdtec_foreignAccountsApprove">
         <id name="resourceid" type="java.lang.String">
            <column name="resourceid" length="32" />
            <generator class="uuid.hex" />
        </id>
        <set name="foreignAccountsApproveChildSet" lazy="true" inverse="true" cascade="all-delete-orphan" order-by="serialNumber">
        	<key>
        		<column name="relationId"></column>
        	</key>
        	<one-to-many class="com.gdcn.gpms.pms.GDTEC.scgl.model.ForeignAccountsApproveChild"/>
        </set> 
    </class>
</hibernate-mapping>


  (N)
<?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">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.gdcn.gpms.pms.GDTEC.scgl.model.ForeignAccountsApproveChild" table="gdtec_foreignAccountsApproveChild">
        <id name="resourceid" type="java.lang.String">
            <column name="resourceid" length="32" />
            <generator class="uuid.hex" />
        </id>
        <property name="subjectRemark" /> 
        <many-to-one name="foreignAccountsApprove" class="com.gdcn.gpms.pms.GDTEC.scgl.model.ForeignAccountsApprove"  cascade="save-update" insert="false" update="false">
        	<column name="relationId"></column>
        </many-to-one>
 
    </class>
</hibernate-mapping>

   :
service_ForeignAccountsApprove.saveEntity(foreignAccountsApprove);
this.dd( foreignAccountsApprove, request) ;
service_ForeignAccountsApprove.updateEntity(foreignAccountsApprove); 

   :

service_ForeignAccountsApproveChild.removeForeignAccountsApproveChildByParentId(foreignAccountsApprove.getResourceid());
service_ForeignAccountsApprove.updateEntity(foreignAccountsApprove);
this.dd( foreignAccountsApprove, request) ;
service_ForeignAccountsApprove.updateEntity(foreignAccountsApprove); 

       :
private void dd(ForeignAccountsApprove fg, HttpServletRequest request) {

	Set<ForeignAccountsApproveChild> childForegin = fg.getForeignAccountsApproveChildSet();
	childForegin.clear();

	String[] subjectRemark = request.getParameterValues("subjectRemark"); //  
	for (int x = 0; x < subjectRemark .length; x++) {
	ForeignAccountsApproveChild foreignAccountsApproveChild 
	        = new ForeignAccountsApproveChild();
	foreignAccountsApproveChild.setSubjectRemark(StringHelper.doWithNull(subjectRemark[x]));
				
	foreignAccountsApproveChild.setForeignAccountsApprove(fg);
	 	
	childForegin.add(foreignAccountsApproveChild);	
	}  
}

좋은 웹페이지 즐겨찾기