I have two entities that have a one-to-one relationship as follows:
Code:
public class ParentTable
{
private long id;
...
@OneToOne(mappedBy="Parent",cascade=CascadeType.ALL)
@JoinColumn(name="id")
public ChildTable getChildTable()
{
return childTable;
}
public void setChildTable(ChildTable childTable)
{
this.childTable=childTable;
}
}
public class ChildTable
{
...
@OneToOne(targetEntity =ParetTable.class)
@JoinColumn(name = "id", nullable = false, insertable=false, updatable=false)
public ParentTable getParentTable() {
return parentTable;
}
public void setParentTable(ParentTable parentTable) {
this.parentTable = parentTable;
}
}
The problem is that in some cases, I want to remove the ChildTable and the ChildTable only.
So this is how I try to do it:
Code:
ParentTable parentTable=(parentTable)getHibernateTemplate().get(ParentTable.class, 12345);
ChildTable childTable=parentTable.getChildTable();
getHibernateTemplate().delete(childTable);
However, the error I get is:
.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)
How do I remove a one-to-one association from an association. If I call childTable.setParentTable(null), it doesn't do any good.
Any idea?[/code]