Hi emmanuel
Thanks for the reply. Here is the example code:
SQL:
create table parent (id number (20) primary key, name varchar2 (255))
create table child (id number (20) primary key, name varchar2 (255), parent_id number (20));
create table sequences (next_value number (20));
Parent.java
public class Parent
{
protected long id;
protected String name;
protected List childs;
public Parent()
{
}
public long getId()
{
return id;
}
public void setId(long newId)
{
id = newId;
}
public String getName()
{
return name;
}
public void setName(String newName)
{
name = newName;
}
public List getChilds()
{
return childs;
}
public void setChilds(List newChilds)
{
childs = newChilds;
}
}
Child.java
public class Child
{
protected long id;
protected String name;
public Child()
{
}
public long getId()
{
return id;
}
public void setId(long newId)
{
id = newId;
}
public String getName()
{
return name;
}
public void setName(String newName)
{
name = newName;
}
}
Test.java
Transaction transaction;
Configuration configuration = new Configuration ();
SessionFactory factory;
Session session;
Parent parent;
Child child;
configuration.addClass (Parent.class);
configuration.addClass (Child.class);
factory = configuration.buildSessionFactory ();
session = factory.openSession ();
parent = new Parent ();
parent.setName ("Example");
transaction = session.beginTransaction ();
session.saveOrUpdate (parent);
transaction.commit ();
session.evict (parent);
parent = (Parent) session.find ("from Parent where name = ?", "Example", Hibernate.STRING).get (0);
session.evict (parent);
child = new Child ();
child.setName ("Example Child");
parent.getChilds ().add (child); // Here it throws the Exception
|