-->
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.  [ 3 posts ] 
Author Message
 Post subject: Dom4J Foreign Key access
PostPosted: Wed May 17, 2006 7:27 pm 
Newbie

Joined: Wed Apr 12, 2006 1:01 pm
Posts: 5
Hello All,
We have 2 tables a POINTER_CACHE and PERSON_ACTIVITY_HEADERS table. We are using the Hibernate Dom4J capabilities and for the most part they are working great.

The Header table is associated with the Cache table using a foreign key. In my code, however, I am unable to extract this foreign key from the DOM4J node that is returned that represents the header table. The abbrieviated mapping file follows:

Code:
<?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>
   <class entity-name="personActivityHeader" table="PERSON_ACTIVITY_HEADERS" node="personActivityHeader" >
      <id name="id" column="ID" node="@id" type="int">
         <generator class="native" />
      </id>
      <property name="submitter" node="submitter" type="string" index="pah_sub" />
      <property name="personFirstName" node="personFirstName" type="string" index="pah_pfn" />
      <property name="personLastName" node="personLastName" type="string" index="pah_pln" />
   </class>
   
   <class entity-name="pointer" table="POINTER_CACHE" node="pointer" >
       <id name="id" column="ID" node="@id" type="int">
          <generator class="native" />
       </id>

       <property name="serializedForm" column="XML_DATA" type="text"  node="serialized" />
      
      <component name="content" node="content" >
         <set name="personActivityHeaders" node="." cascade="all" embed-xml="true">
            <key column="pointerId" not-null="true"/>
            <one-to-many entity-name="personActivityHeader" node="personActivityHeader"/>
         </set>
      </component>
   </class>
   
</hibernate-mapping>


Then I retrieve the node as XML with the following Java code snippet:


Code:
         List l = getHibernateTemplate().findByCriteria(searchCriteria);
         Iterator i = l.iterator();
         int recordCount = 0;
         while(i.hasNext()) {
            Element e = (Element)i.next();
            Element f = (Element)getHibernateTemplate().get("pointer", Integer.valueOf(e.attribute("id").getStringValue()));
                        }


My question is, how do I get data from the "pointer" table using the "pointerId" foriegn key? When I print the Element 'e' that I retrieve from the database it looks like this:

<personActivityHeader id="166">
<personFirstName>Charley</personFirstName>
<personLastName>Test2</personLastName>
</personActivityHeader>

I can not, however, get the 'pointerId' out.

I inherited this code and I am learning as I go along so any assistance would be much appreciated.

Thanks!

Yogesh[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 7:40 pm 
Newbie

Joined: Wed Apr 12, 2006 1:01 pm
Posts: 5
I should point out that the following line of code is where I would like to get the 'pointerId' rather that just the field 'id':

Code:
Element f = (Element)getHibernateTemplate().get("pointer", Integer.valueOf(e.attribute("id").getStringValue()));


The reason that code worked is because the 'id' and 'pointerId' were the same value in my database... When the 'id' and 'pointerId' are different (this happened upon upgrading to Oracle 10g), then the code doesn't work.

Thanks!

Yogesh


Top
 Profile  
 
 Post subject: Found a Solution!
PostPosted: Wed May 17, 2006 8:24 pm 
Newbie

Joined: Wed Apr 12, 2006 1:01 pm
Posts: 5
Hello,
I added this to my PERSON_ACTIVITY_HEADERS class:

Code:
<property name="pointerIdNode" type="int" >
   <formula>pointerId</formula>
</property>      


Now I can simply access this element in my code:

Code:
Element f = (Element)getHibernateTemplate().get("pointer", Integer.valueOf(e.element("pointerIdNode").getStringValue()));


Does this make sense?

Thanks!

Yogesh


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

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.