aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Many to One XML Mapping giving unwanted results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Many to One XML Mapping giving unwanted results" Watch "Hibernate Many to One XML Mapping giving unwanted results" New topic
Author

Hibernate Many to One XML Mapping giving unwanted results

Navdeep Singh kanwal
Greenhorn

Joined: Dec 19, 2011
Posts: 9
I have 2 Tables
Table 1: Employee
column1:INDEX_NO
...
.....
columnN:description (foreign Key to Designation INDEX_NO)

Employee.hbm.xml:

<hibernate-mapping package="com.salary.model">
<class name="Employee" table="EMPLOYEE">
<id name="index_no" column="INDEX_NO">
<generator class="identity" />
</id>
<property name="emp_id" not-null="true" unique="true" column="EMP_ID" />

<many-to-one name="designationDescription" fetch="join" class="com.salary.model.Designation">
<column name="DESIGNATION" not-null="true" />
</many-to-one>


</class>


Employee.java

public class Employee {
private Long index_no;
public Integer designation;
private Designation designationDescription=new Designation();
//getter and setter
}
Table 2: Designation
column1: INDEX_NO
...
columnN: Description

Designation.hbm.xml

<class name="Designation" table="DESIGNATION">
<id name="indexNo" column="INDEX_NO">
<generator class="identity" />
</id>
<property name="coreValue" column="CORE_VALUE" />
<property name="description" column="DESCRIPTION" />

<!-- <set name="employees" table="Employee"
inverse="true" lazy="true" fetch="join">
<key>
<column name="INDEX_NO" not-null="true"/>
</key>
<one-to-many class="com.salary.model.Employee"/>
</set>
-->
</class>

Everything is fine till now:
But when i try to fetch it in my java class with following statement:
empList = session.createQuery("select e from Employee as e ").list();

i am gettting designationDescription having null values and some unwanted handler object ..see attachment for debugging mode snapshot .
This object is of Type Designation and it should contain INDEX_NO,Description in it but they are null as of now and some unwanted object is visible in debugging mode.


[Thumbnail for debugSnap.png]

Navdeep Singh kanwal
Greenhorn

Joined: Dec 19, 2011
Posts: 9
This is called Lazy Loading from Hibernate. Just try to fetch the child and you will that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Many to One XML Mapping giving unwanted results