java - Hibernate One to One relationship wrong -
i have relationship
@onetoone(cascade = cascadetype.all, fetch = fetchtype.eager, mappedby = "candidacy") @xmlelement @getter @setter private informcandidacy informcandidacy; @onetoone @joincolumn(name = "candidacy_id", nullable = false, insertable = false, updatable = false) @getter @setter private candidacy candidacy;
on database declare fk
<addforeignkeyconstraint basecolumnnames="candidacy_id" basetablename="inform_candidacy" constraintname="fk_candidacy_inform_candidacy" ondelete="cascade" onupdate="cascade" referencedcolumnnames="id" referencedtablename="candidacy"/>
but when try persist on cascade candidacy , save informcandidacy first time not exist on database yet, relationship between them not created , informcandidacy null candidacy
@override public void saveall(final list<candidacy> candidacies) { (candidacy candidacy : candidacies) { candidacy candidacydb = findbyid(candidacy.getid()); candidacy.getinformcandidacy().setcandidacy(candidacydb); candidacydb.setinformcandidacy(candidacy.getinformcandidacy()); candidacyrepository.save(candidacydb); } }
and in table of informcandidacy dont have relationship candidacy
*************************** 1. row *************************** id: 101 candidacy_id: null <--------- wtf! selected_number: null information_letter: null selection_decision: null selectionreport: 2014-06-28
what i´m doing wrong.
regards.
your mapping tells hibernate not insert or update "candidacy_id" column (insertable = false, updatable = false). try way :
@onetoone @joincolumn(name = "candidacy_id", nullable = false) @getter @setter private candidacy candidacy;
Comments
Post a Comment