java - HIbernate update with null on onetomany relation -
i have following tables :
- product (id_product, name)
- property (id_property, name)
- product_properties (id_product, id_property)
(all fields not nullable)
and following hibernate mapping :
class product { @id private integer id; @onetomany(mappedby="product") @cascade({cascadetype.all}) private set<productproperties> productproperties = new hashset<productproperties)(0); (...) }
when update product class adding or removing rows "productproperties" field, rows updated correctly in product_properties table.
the problem when "productproperties" null or empty, hibernate throws constraintviolationexception.
since need "productproperties" empty sometimes, there proper solution problem (something @zerotomany annotation) ?
the answer given dev blanked in comments. solution :
@onetomany(mappedby="foo", orphanremoval=true)
Comments
Post a Comment