Table
Mproduct
product_id int
name
price
Mproduct_config_value
desc_id int
product_id int
value
Mproduct_config_desc
desc_id int
name
descript
Mapping
Code:
<set name="configDescObjBridge" lazy="true" inverse="true" table="mproduct_config_value" cascade="all" order-by="PRODUCT_ID">
<key column="PRODUCT_ID"/>
<composite-element class="com.cubetech.bus.bean.associate.BridgeConfigDesc">
<parent name="product"/>
<many-to-one name="desc" column="DESC_ID" class="MproductConfigDesc" not-null="true"/>
<property name="value" insert="true" update="true" column="VALUE" not-null="true" type="java.lang.String"/>
</composite-element>
</set>
CodeCode:
_RootDAO.initialize();
SessionFactory sf = _RootDAO.getSessionFactory();
Session session = sf.openSession();
Transaction tx = null;
tx = session.beginTransaction();
Mproduct prod = (Mproduct)session.load(Mproduct.class, new Integer(1));
for(BridgeConfigDesc bridge:prod.getConfigDescObjBridge()){
System.out.println(bridge.getDesc().getId());
if(bridge.getDesc().getId()==3){
bridge.setValue("test");
}
}
session.saveOrUpdate(prod);
tx.commit();
session.flush();