-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem Returning rows from table
PostPosted: Tue Feb 28, 2006 4:36 pm 
Newbie

Joined: Tue Feb 28, 2006 4:14 pm
Posts: 2
Location: Florida, USA
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I have a query that returns 6 rows - which is correct - but each instance of PromoHeadingsHolder.class contains the data from row 1. I have tried many combinations, but same result. The PK on the table consists of the first 2 columns in the mapping document and the associated index is specified in the <generator> tag.
The code is wrapped by a try block, and the session close is in the finally block.
Help VM appreciated.
I am using Hibernate v2 , Oracle 8 and WebLogic 7

Here is a section of my mapping document
<class name="com.jnjvision.common.promo.dbo.PromoHeadingsHolder" table="PROMO_SURVEY_INTRO_TEXT" >
<meta attribute="class description">
Represents a text heading or text paragraph rendered above the demographics
section in the freetrial web page.
</meta>
<id name="surveyPromoId" type="long" unsaved-value="null">
<column name="PROMO_SURVEY_ID" length="10" />
<generator class="sequence">
<param name="sequence">PK_PROMO_SURVEY_INTRO_TEXT</param>
</generator>
</id>
<property name="paragraphSequenceNumber" type="int">
<column name="PARAGRAPH_SEQ_NO" length="2" not-null="true" />
</property>
<property name="resourceChannel" type="string">
<column name="RESOURCE_CHANNEL" length="2" />
</property>
/b

And here is the code:
List list = session.createCriteria(PromoHeadingsHolder.class)
.add(Expression.eq("surveyPromoId", promoId))
.add(Expression.ge("paragraphSequenceNumber",
new Integer(startingParagraphSeqNo)))
.add(Expression.le("paragraphSequenceNumber",
new Integer(endingParagraphSeqNo)))
.addOrder( Order.asc("paragraphSequenceNumber"))
.list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 28, 2006 4:59 pm 
Beginner
Beginner

Joined: Fri Jul 30, 2004 2:53 pm
Posts: 33
Location: Washington, DC
What does the query that hibernate generates look like? What does the data that the query returns (when executed in a regular SQL tool) look like?

BTW - You can save yourself som typing by using Expression.between instead of Expression.ge & Expression.le


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 28, 2006 5:32 pm 
Newbie

Joined: Tue Feb 28, 2006 4:14 pm
Posts: 2
Location: Florida, USA
When returned in a regular query it looks correct - 6 rows, all different.
I was using the 'between' clause, but it got lost in the debugging I've been doing.
I have also tried these two with same result:
List list = session.createQuery(
"from PromoHeadingsHolder p where p.surveyPromoId=:promoId")
.setEntity("surveyPromoId", promoId)
.list();

Query query = session.createQuery(sb.toString());
List list = query.list();

The result is the same - 6 identical rows


Top
 Profile  
 
 Post subject: Found the Same Problem...
PostPosted: Wed Mar 01, 2006 3:59 pm 
Newbie

Joined: Mon Aug 29, 2005 5:01 pm
Posts: 5
I ran into this problem yesterday and in a seperate project a few months back using a mapping with a composite-id, but didn't have time to followup on the forums until now. Perhaps an error in the composite-id definition? My example also returns a list with the correct object count, but the objects(rows) all equal the first. If you find a solution, could you please post?


Using hibernate 3.0.1 and spring 1.2.1:

A snippet from the mapping file:
<class
name="com.biz.Bid"
table="bid"
mutable="false"
>
<cache usage="read-only"></cache>

<composite-id >
<key-property
name="eventId"
column="event_id"
type="java.lang.String"
length="4"
>
</key-property>

<key-property
name="bidTime"
column="bid_time"
type="int"
>
</key-property>
<key-property
name="itemNum"
column="item_num"
type="short"
>
</key-property>
</composite-id> ...

Here's the java code snippet (In class extending Spring HibernateDaoSupport):

public List select(final Bid obj ) throws HibernateException {
return (List) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session hibSession) throws HibernateException {
List retval = new ArrayList();
StringBuffer hql = new StringBuffer("from Bid bid WHERE bid.eventId ='"+obj.getEventId()+" AND bid.itemNum = "+obj.getItemNum());
retval = hibSession.createQuery( hql.toString() ).list();

return retval;
}
}
);
}

The generated query string:

from Bid bid WHERE bid.eventId ='MYEVENT' AND ( bid.itemNum = 210 )



Thanks,
PT


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