java - Hibernate Add Model with OneToMany -
i have got personmodel has address.
looks that:
public class personmodel { @manytoone(fetch = fetchtype.lazy) private addressmodel address; } public class addressmodel { private string street; private string city; @onetomany(fetch = fetchtype.lazy, mappedby = "address", cascade = cascadetype.all) private set<personmodel> persons; }
now, when json client:
{ "person": { "address": { "street": "examplestreet", "city": "examplevillage" } } }
and try save that:
personmodelrepository.save(myjson.person);
hibernate throw transientpropertyvalueexception.
object references unsaved transient instance - save transient instance before flushing
do have save every single db-entry related person first or there way?
try adding cascadetype.all
@ @manytoone
annotation.
this achieves person gets saved automatically if save address
Comments
Post a Comment