-->
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: How to get data from Child table?
PostPosted: Fri Sep 05, 2008 8:56 pm 
Newbie

Joined: Wed Sep 03, 2008 11:39 am
Posts: 4
Here is my code :

Hibernate version:3.2

Parent.hbm.xml
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 package="com.db">
   <class name="Parent" table="PARENT_TABLE">
      <id name="requestId" column="REQUEST_ID">
         <generator class="sequence">
            <param name="sequence">SEQ1</param>
         </generator>
      </id>
      <property name="statusCode" column="ST_CODE" />
   </class>
</hibernate-mapping>



public class Parent {
   private int requestId;
   private String statusCode;
   private String message;
....getters & setters
}


and Child.hbm.xml
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 package="com.db">
   <class name="Child" table="CHILD_TABLE">
      <id name="childId" column="CHILD_ID">
         <generator class="sequence">
            <param name="sequence">SEQ2</param>
         </generator>
      </id>
      <property name="message" column="MESSAGE" />
      <property name="messageType" column="MESSAGE_TYPE" />
      <property name="requestId" column="REQUEST_ID" />
   </class>
</hibernate-mapping>




public class Child {
   private int childId = 0;
   private int requestId = 0;
   private String message = "";
   private String messageType = null;

....getters & setters
}



My requirements are :

I want the data for the Parent's "message" attribute and for that I want to fetch the Parent object from the database, w/o making extra call to Child table. How can I do that ? Is there any way?


In short I want to construct my where clause using hibernate as :
parent.requestId = child.requestId(+)
and parent.statusCode = child.messageType(+)
and child.messageType = 'SOME_VALUE' /* I want to hardcode this 'SOME_VALUE' into the xml file ...if possible. */

I do not want to use the custom sql. Also every time I load the Parent table , it should fetch the data for message.


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.