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

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -