java - implementing one to many relationship encourage this exception: During synchronization a new object was found through a relationship -
i have 2 entity classes have 1 many relationship. suggestion , suggestionscope classes. (1 suggestion has 1 suggestion scope 1 suggestion scope used in many suggestion) want implement using jpa. implemented this:
public class suggestion { @id @sequencegenerator(name = "suggestion_sequence_generator", sequencename = "suggestion_seq", initialvalue = 1, allocationsize = 1) @generatedvalue(strategy = generationtype.sequence, generator = "suggestion_sequence_generator") @xmlelement(name = "id") @column(name = "id", nullable = false) private long id; @manytoone( fetch = fetchtype.lazy) @joincolumn(name = "fk_suggestion_scope") @xmlelement(name = "fk_suggestion_scope") private suggestionscope suggestionscope; ... }
this child side , in parent side have not used relational annotation, when try run it, exception:
java.lang.illegalstateexception: during synchronization new object found through relationship not marked cascade persist: suggestionscope{id=null, name='null'}.
i have added part child side:
@manytoone( fetch = fetchtype.lazy,cascade = cascadetype.persist) @joincolumn(name = "fk_suggestion_scope") @xmlelement(name = "fk_suggestion_scope") private suggestionscope suggestionscope;
by time run it, 1 one relation!!; each record of child table persisting 1 parent also!
thanks in advance
Comments
Post a Comment