Hi,
I have a bidirectional relationship between two classes
mapping in the parent class...
Code:
<hibernate-mapping>
<class name="com.testhibernate.Performer" table="PERFORMER">
.......
<bag name="showList" cascade="all-delete-orphan" lazy="false" inverse="true">
<key column ="PERFORMER" />
<one-to-many class="com.testhibernate.Show" />
</bag>
</class>
</hibernate-mapping>
and
in the child class it is
Code:
<hibernate-mapping>
<class name="com.testhibernate.Show" table="SHOW">
....
<many-to-one name="performer" class="com.testhibernate.Performer" not-null="true">
<column name="PERFORMER"/>
</many-to-one>
</class>
</hibernate-mapping>
The following code tries to emulate the object handling (atleast in my project) using http request
Code:
//Fetch mode
session = sf.openSession();
tx = session.beginTransaction();
perf = (Performer) session.get(com.gauravcj.testhibernate.Performer.class, 1l);
tx.commit();
session.close();
// Detached mode
System.out.println("Performer:"+perf.getName());
System.out.println(perf.getShowList().get(0).getName());
// supposing only one show is taken out of a list of size five
Show s = perf.getShowList().get(0);
//Since this data is recreated from HTTP Request a new list is created
List <Show> showList = new ArrayList <Show>();
showList.add(s);
perf.setShowList(showList);
//Update
session = sf.openSession();
tx = session.beginTransaction();
session.saveOrUpdate(perf);
tx.commit();
session.close();
Now since a new List is created, the cascade does not work.
How should I go about handling lists in Web-based applications?
References to the right article are welcome.