hi,
I am having some problem saving an object that contains an object that is already saved in the database. e.g. I have a class A that has a Code. These codes are entered earlier and whenever an object of type A is made, an object of type Code is assigned to it.
@Entity(access=AccessType.FIELD)
public class A
{
@OneToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.PERSIST})})
@JoinColumn(name="CodeID")
private Code code;
public void setCode(Code c)
{
this.code = c;
}
public Code getCode()
{
return this.code ;
}
}
@Entity(access=AccessType.FIELD)
public class Code
{
String description;
String codeNumber;
}
The problem is that when i save object of class A, it gives me an exception of duplicate entry for the object of code
what am i doing wrong?? kindly reply asap if you know the solution..
|