Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hey all,
Am using Hibernate3's new feature to populate XML into db. I can save the root tag but not able to save child tags.
The xml which am trying to save is:
<tns:Trade id="123" quantity="100.0" security="912828BK5"
xmlns:tns="http://mymachine/TRP/Trade"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mymachine/TRP/Trade Trade.xsd ">
<Allocation id="124" portfolio="ABC" quantity="10.0" />
<Allocation id="125" portfolio="ABD" quantity="20.0" />
<Allocation id="126" portfolio="ABE" quantity="20.0" />
<Allocation id="127" portfolio="ABF" quantity="50.0" />
</tns:Trade>
Mapping docs for these tags (Trade and Allocation are given below).
I dont have Trade Id as the instance member in Allocation, nor does my Allocation.hbm.xml has it.
Am new to Hibernate, so dont know if this is the right way to do it.
Pls help!!!
Hibernate version: 3.1
Mapping documents:
This is the Trade.hbm.xml:
<hibernate-mapping>
<class name="demo.Trade" entity-name="Trade">
<id name="id" node="@id">
<generator class="native"></generator>
</id>
<property name="Quantity" column="Quantity" node="@quantity" />
<property name="Security" column="Security" node="@security"></property>
<set name="allocations" table="Allocation" cascade="save-update">
<key column="TradeId"></key>
<one-to-many
class="demo.Allocation" node="Allocation" entity-name="Allocation"/>
</set>
</class>
</hibernate-mapping>
Mapping for Allocation
<hibernate-mapping>
<class name="demo.Allocation" entity-name="Allocation">
<id name="id" node="@id">
<generator class="native"></generator>
</id>
<property name="Quantity" column="Quantity" node="@quantity"></property>
<property name="Portfolio" column="Portfolio" node="@portfolio"></property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
session = HibernateUtil.getSessionFactory().openSession();
transaction = session.beginTransaction();
dom4jSession = session.getSession(EntityMode.DOM4J);
Iterator iter = trades.iterator();
while (iter.hasNext())
{
Object next = iter.next();
dom4jSession.save(next);
}// end while
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: