Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1 beta 3
Mapping documents:
--------------------------------WORK REQUEST--------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="WorkRequest"
table="reqst"
node="WorkRequest"
>
<id
name="id"
type="java.lang.Integer"
column="reqst_intid"
node="@Id"
>
<generator class="assigned" />
</id>
<property
name="priority"
type="java.lang.Short"
column="priority"
not-null="true"
length="6"
node="@Priority"
/>
<property
name="type"
type="java.lang.String"
column="reqst_type"
not-null="true"
length="20"
node="@type"
/>
<property
name="state"
type="java.lang.Short"
column="reqst_state"
length="6"
/>
<!-- Associations -->
<!-- bi-directional one-to-many association to Instruction -->
<set
name="instructions"
lazy="true"
inverse="true"
cascade="all"
node="."
>
<key>
<column name="reqst_intid" />
</key>
<one-to-many
class="Instruction"
node="Instruction"
/>
</set>
</class>
</hibernate-mapping>
------------------------INSTRUCTION---------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="Instruction"
table="instruction"
node="Instruction"
>
<id
name="id"
type="java.lang.Integer"
column="instruction_intid"
>
<generator class="increment" />
</id>
<property
name="sequenceNumber"
type="java.lang.Short"
column="instruction_seq_nbr"
not-null="true"
length="6"
node="@SequenceNumber"
/>
<!-- Associations -->
<!-- bi-directional many-to-one association to Reqst -->
<many-to-one
name="request"
class="WorkRequest"
not-null="true"
node="WorkRequest"
>
<column name="reqst_intid" />
</many-to-one>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session dom4jSession = openSession.getSession(EntityMode.DOM4J);
Transaction tx = openSession.beginTransaction();
SAXReader reader = new SAXReader();
Document document = reader.read(new File(m_xmlInputFile));
Element rootElement = document.getRootElement();
dom4jSession.persist(rootElement.getName(),rootElement);
dom4jSession.flush();
tx.commit();
Full stack trace of any exception that occurs:
Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):
[java] Hibernate: select max(instruction_intid) from instruction
[java] Hibernate: insert into reqst (priority, reqst_type, reqst_state, req
st_intid) values (?, ?, ?, ?)
[java] Hibernate: insert into instruction (instruction_seq_nbr, reqst_intid
, instruction_intid) values (?, ?, ?)
Debug level Hibernate log excerpt:
------------------------------------------------------------------
I'm trying to use the new dom4j persistence features to map a bidirectional one-to-many. Its not setting the foreign key in the child. When I change the relationship to unidirectional one-to-many it does set it (with an additional update of course).
Any ideas of why this might be happening?
Thanks! Here is the XML I'm trying to ingest...
<?xml version="1.0" encoding="UTF-8"?>
<WorkRequest Id="987654321" Priority="89" type="Ingest">
<Instruction SequenceNumber="1">
</Instruction>
</WorkRequest>