This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Many to One XML Mapping giving unwanted results

 
Navdeep Singh kanwal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
debugSnap.png
[Thumbnail for debugSnap.png]
 
Navdeep Singh kanwal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is called Lazy Loading from Hibernate. Just try to fetch the child and you will that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic