Hi
I am having one to many relationship between an employee and language which has been defined as below
Employee Mapping
Code:
<hibernate-mapping>
<class name="TP_Employee" table="TP_EMPLOYEE">
<id name="emplid" type="string" column="EMPLID" />
<property name="busFirstName" column="BUS_FIRST_NAME" type="string" length="50" />
<property name="busLastName" column="BUS_LAST_NAME" type="string" length="50" />
<property name="busEmailAdd" column="BUS_EMAIL_ADDRESS" type="string" length="70" />
<property name="busPhone" column="BUS_PHONE" type="string" length="24" />
<property name="fullPartTime" column="FULL_PART_TIME" type="string" length="1" />
<list name="languages" table="TP_EMP_LANGUAGES">
<key column="emplid"/>
<index column="language" />
<one-to-many class="TP_Emp_Languages"/>
</list>
</class>
</hibernate-mapping>
Language mapping
Code:
<hibernate-mapping>
<class name="TP_Emp_Languages" table="TP_EMPLOYEE_LANGUAGES">
<id name="id" type="long" column="id" ></id>
<property name="isPrimary" column="IS_PRIMARY" type="string" />
<property name="accomplishment" column="ACCOMPLISHMENT" type="string" />
</class>
</hibernate-mapping>
Retriving employee details
Code:
public TP_Employee getEmployeeDetails(String gpn){
Session session = SessionUtil.getInstance();
try{
Transaction transaction = session.beginTransaction();
String queryString = "from TP_Employee where emplid = :emplid";
Query query = session.createQuery(queryString);
query.setInteger("emplid", Integer.parseInt(gpn));
TP_Employee employee = (TP_Employee)query.uniqueResult();
List<TP_Emp_Languages> language = employee.getLanguages();
System.out.println(language.size());
return employee;
} catch (HibernateException he) {
he.printStackTrace();
}
return null;
}
However retrive of employe record does not bring back any langauge details. The list size is always zero in this case. Is my query right or am I missing something in retrival process ?
--Manoj