java - How does hibernate decide update/save associated objects -
anyone me explain hibernate. how save/update child objects when save/update parent object. especially, child object @embeddedid mapping
@embeddable public class bomlevelkey implements serializable{ /** * */ private static final long serialversionuid = 1l; item item; long organizationid; item componentitem; @column(name = "organization_id") public long getorganizationid() { return organizationid; } public void setorganizationid(long organizationid) { this.organizationid = organizationid; } @manytoone @joincolumn(name = "inventory_item_id") public item getitem() { return item; } public void setitem(item item) { this.item = item; } @manytoone @joincolumn(name = "component_item_id") public item getcomponentitem() { return componentitem; } public void setcomponentitem(item componentitem) { this.componentitem = componentitem; } @override public boolean equals(object obj) { if (obj == null || !(obj instanceof bomlevelkey)) { return false; } bomlevelkey key = (bomlevelkey) obj; if (key.getitem().getinventoryitemid() == this.getitem() .getinventoryitemid() && key.getcomponentitem().getinventoryitemid() == .getcomponentitem().getinventoryitemid() && key.getorganizationid() == this.getorganizationid()) { return true; } return false; } } @entity @table(name = "es_bom_levels", schema = "xx_vms") public class itemconversionattributes implements serializable{ /** * */ private static final long serialversionuid = 1l; private double componentroutingyield; private double forwardroutingyield; private double conversionfactor; private double cumulativeleadtime; private integer organizationid; private item componentitem; private bomlevelkey id; @embeddedid public bomlevelkey getid() { return id; } public void setid(bomlevelkey id) { this.id = id; } /** * @hibernate.property * column="component_routing_yield" * **/ @column(name="component_routing_yield") public double getcomponentroutingyield(){ return componentroutingyield; } public void setcomponentroutingyield(double componentroutingyield){ this.componentroutingyield= componentroutingyield; } /** * @hibernate.property * column="forward_routing_yield" * **/ @column(name="forward_routing_yield") public double getforwardroutingyield(){ return forwardroutingyield; } public void setforwardroutingyield(double forwardroutingyield){ this.forwardroutingyield = forwardroutingyield; } /** * @hibernate.property * column="conversion_factor" * **/ @column(name="conversion_factor") public double getconversionfactor(){ return conversionfactor; } public void setconversionfactor(double conversionfactor){ this.conversionfactor = conversionfactor; } /** * @hibernate.property * column="cumulative_lead_time" * **/ @column(name="cumulative_lead_time") public double getcumulativeleadtime(){ return cumulativeleadtime; } public void setcumulativeleadtime(double cumulativeleadtime){ this.cumulativeleadtime = cumulativeleadtime; } /** * @hibernate.property * column="organization_id" * **/ @column(name="organization_id", insertable = false, updatable = false) public integer getorganizationid(){ return organizationid; } public void setorganizationid(integer organizationid){ this.organizationid = organizationid; } /** * @hibernate.many-to-one * column="component_item_id" * insert="false" * update="false" * **/ @manytoone(targetentity=item.class) @joincolumn(name="component_item_id", insertable=false, updatable=false) @notfound(action=notfoundaction.ignore) public item getcomponentitem(){ return componentitem; } public void setcomponentitem(item componentitem){ this.componentitem = componentitem; }
}
in class item, i've mapping:
@onetomany(mappedby = "id.item") @mapkey(name = "id.componentitem") public map<item, itemconversionattributes> getconversionattributes(){ return conversionattributes; } public void setconversionattributes(map<item, itemconversionattributes> conversionattributes) { this.conversionattributes = conversionattributes; }
save/update nothing.
its based on dao objects primary key's value.
if set default value , hibernate add otherwise update
Comments
Post a Comment