I have the following jpa class :
/**
*
*/
package ro.spad.web.registrucasa.client.model;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* @author vp@spad.ro
*
*/
@Entity
@Table(name = "registrudecasa")
public class RegistruDeCasa implements Serializable, IsSerializable {
private int myid;
private Date data;
private List<LinieRegistru> liniiRegistru;
private PunctDeLucru punctDeLucru;
private User userBasic;
private User userExpert;
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public int getMyid() {
return myid;
}
public void setMyid(int myid) {
this.myid = myid;
}
@Column (length = 100, nullable = false)
public void setData(Date data) {
this.data = data;
}
public Date getData() {
return data;
}
@OneToMany (fetch = FetchType.LAZY)
@JoinTable(name = "registrudecasa_linieregistru", joinColumns = @JoinColumn(name = "registrudecasa_myid"), inverseJoinColumns = @JoinColumn(name = "linieregistru_myid"))
public List<LinieRegistru> getLiniiRegistru() {
return liniiRegistru;
}
public void setLiniiRegistru(List<LinieRegistru> liniiRegistru) {
this.liniiRegistru = liniiRegistru;
}
@OneToOne (cascade = CascadeType.ALL)
@JoinColumn(name="PUNCTDELUCRU_MYID", nullable = true, insertable = true, updatable = true)
public PunctDeLucru getPunctDeLucru() {
return punctDeLucru;
}
public void setPunctDeLucru(PunctDeLucru punctDeLucru) {
this.punctDeLucru = punctDeLucru;
}
@OneToOne (cascade = CascadeType.ALL)
@JoinColumn(name="USER_BASIC_MYID", nullable = false, insertable = true, updatable = true)
public User getUserBasic() {
return userBasic;
}
public void setUserBasic(User userBasic) {
this.userBasic = userBasic;
}
@OneToOne (cascade = CascadeType.ALL)
@JoinColumn(name="USER_EXPERT_MYID", nullable = true, insertable = true, updatable = true)
public User getUserExpert() {
return userExpert;
}
public void setUserExpert(User userExpert) {
this.userExpert = userExpert;
}
}
I'm having a problem when saving or deleting an entity "RegistruDeCasa". The problem is that this entity has a reference to an entity called userExpert(class : User) and when I'm trying to save or delete a "RegistruDeCasa" my application tryes also to update or delete the expertUser. Is this a matter of JPA and annotations? I'm not very sure .... maybe it's something regarding Hibernate (my application also uses Hibernate) but I don't know for sure......Can somebody help me? This problem also persist whenever I try to save an entity that has one to one relations to another entity( for example in this class : punctDeLucru,userBasic,userExpert).
Thanks in advance,
Bogdannb