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.