-->
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.  [ 2 posts ] 
Author Message
 Post subject: NamedQuery problem with multiple rows in result set
PostPosted: Tue Jun 20, 2006 6:42 am 
Newbie

Joined: Thu May 04, 2006 12:12 pm
Posts: 4
Hi,

I have successfully managed to call a stored procedure from Hibernate that returns multiple rows. The problem I discovered however, is that I am getting multiple copies of the 1st row in the result set.
I do get the correct number of rows.

Calling the sp outside of hibernate returns the right number of rows and data.

Any ideas?

Many thanks.

Jadiyo


Hibernate version: 3.1.1

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping default-lazy="true" >

<class
name="PumaSelFndBmkIA"
>
<id
name="policyNo"
type="java.lang.String"
column="policy_no"
>
<generator class="assigned" />
</id>

<property
name="policySubnumber"
type="java.lang.String"
column="policy_subnumber"
not-null="false"
length="50"
>
</property>
<property
name="managedFundCode"
type="java.lang.String"
column="managed_fund_code"
not-null="false"
length="50"
>
</property>
<property
name="fundId"
type="int"
column="fund_id"
not-null="false"
length="10"
>
</property>
<property
name="priceMid"
type="java.math.BigDecimal"
column="price_mid"
not-null="false"
>
</property>
</class>

<sql-query name="puma_sel_fnd_bmk_ia" callable="true">
<return alias="svo2" class="PumaSelFndBmkIA">
<return-property name="policyNo" column="policy_no"/>
<return-property name="policySubnumber" column="policy_subnumber"/>
<return-property name="managedFundCode" column="managed_fund_code"/>
<return-property name="priceMid" column="price_mid"/>
<return-property name="fundId" column="fund_id"/>
</return>
{ call my_sp( :Benchmarks_Only, :Policy_No, :Policy_Subnumber) }
</sql-query>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Query query = session.getNamedQuery("my_sp");
query = query.setInteger("Benchmarks_Only", 2);
query = query.setString("Policy_No", "31128");
query = query.setString("Policy_Subnumber", "003");

List list = query.list();
session.flush();
session.close();
if (list != null) {
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
PumaSelFndBmkIA ia = (PumaSelFndBmkIA) iterator.next();
System.out.println("ia = " + ia);
}
} else {
System.out.println("list is null");
}


Name and version of the database you are using:
Sybase 12.5


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 11:35 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Move the session.close() to after the loop.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.