• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Many to One XML Mapping giving unwanted results

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is called Lazy Loading from Hibernate. Just try to fetch the child and you will that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic