These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: OneToMany association pron
PostPosted: Wed Nov 24, 2010 6:13 am 
Beginner
Beginner

Joined: Tue Sep 28, 2010 5:14 am
Posts: 25
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.