-->
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.  [ 3 posts ] 
Author Message
 Post subject: sql-query mapping for muldtiple rows.
PostPosted: Sat Mar 25, 2006 6:23 am 
Newbie

Joined: Sat Mar 25, 2006 5:12 am
Posts: 6
Location: Pune
Hi All,
I have tried using named sql querries for mapping its resultset using hibernate to my class. For this,
1> i have created a class "Employee" having properties
empId
deptId
empName
salary
2> wrote a mapping for it in "Employee.hbm.xml" which is as follows:
<hibernate-mapping>
<class name="com.pharmquest.provantis.bean.Employee">
<id name="empId" type="int" >
<generator class="sequence"/>
</id>

<property name="deptId" type="int"/>
<property name="empName" type="string"/>
<property name="salary" type="int"/>
</class>

<sql-query name="selectEmployee">
<return alias="p" class="com.pharmquest.provantis.bean.Employee">
<return-property name="empId" column="dept_id"/>
<return-property name="deptId" column="emp_id"/>
<return-property name="empName" column="emp_name"/>
<return-property name="salary" column="salary"/>
</return>
select * from employee
</sql-query>

</hibernate-mapping>

Now the problem is whenever the result set contains only one result(query returns single row) it works fine as in resultset has correct values but if it tried to select multiple rows as in the example ("select *") the result set is having only first record as in say query returns two recors (for emp1 and emp2) but whenever i tried iterating the result set and try to display values it shows me emp1,emp1 instead of emp1,emp2.

The sequence of commands to execute this are
String qry = "selectEmployee";
SQLQuery query = (SQLQuery) session.getNamedQuery(qry);
List employees = query.list();

Please help me resolving this issues,or is it that i just can't map multiple rows.

thanx in advance.

_________________
Yuvi


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 12:27 am 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
post your code that does the iteration too.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 5:26 am 
Newbie

Joined: Sat Mar 25, 2006 5:12 am
Posts: 6
Location: Pune
Hi,
Thanx for replying , the next day i was myself reviewing my code and find out the error, hibernate is just fine it was me who is making the mistake, i have mapped "emp_id" to "dept_id" and dept id is same for all the records so hibernate is getting confuse. now i did correct my mappings and got the correct result.

Thanx once again...

_________________
Yuvi


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

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.