vendredi 20 mars 2015

Hibernate 2 records being inserted for Single JAVA Object

I am using Hibernate Implementation of JPA with Spring.



Class Country{

@OneToMany(mappedBy="Country", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
List<State> stateList;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "Current_State_ID")
State currnetState;

}


State stateObj = new State();
country.getStateList().add(stateObj);

country.setCurrnetState(stateObj);


This creates 2 entries for in State Table, which messes up my logic. Can someone please point me what I am doing worng.


Aucun commentaire:

Enregistrer un commentaire