-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: XML Node settings for bidirectional one-to-many
PostPosted: Fri Sep 16, 2005 4:35 pm 
Newbie

Joined: Fri Mar 04, 2005 2:02 pm
Posts: 18
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.