-->
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: session.list() outputs Entity list with same values
PostPosted: Wed Dec 23, 2009 9:33 pm 
Newbie

Joined: Wed Aug 06, 2008 2:18 pm
Posts: 5
I'm attempting to get a list of entities, but the returned collection contains multiple objects with all the same values.

When I get the same list of just object arrays (without the "addEntity" call), the collection correctly contains all different values.

When I execute the query against the database directly, I correctly get a recordset with all different values.

Is there a reason why the following code would return multiple objects with all the same values (the values of the first row in the resultset) when the resultset that's returned has rows with all different values?:

session.createSQLQuery(select * from testTable).addEntity(TestModel.class).list();

Thanks!


Top
 Profile  
 
 Post subject: Re: session.list() outputs Entity list with same values
PostPosted: Wed Dec 23, 2009 11:59 pm 
Newbie

Joined: Wed Aug 06, 2008 2:18 pm
Posts: 5
I've tried three different queries and the list of entities always comes back with duplicate values where the object array is correct:

Code:
Query query1 = session.createQuery(" from testTable WHERE userId=:userID");
query1.setParameter("userID", userId);
List hqlList = query1.list();
                  
SQLQuery query2 = session.createSQLQuery("select * from testTable where userId=:userID").addEntity(TestTable.class);
query2.setParameter("userID", userId);
List sqlList = query2.list();

SQLQuery query3 = session.createSQLQuery("select * from testTable where userId=:userID");
query3.setParameter("userID", userId);
List objArray = query3.list();


Only query3 (the object array) returns correct with different records, the contain duplicate objects of the first record.


Top
 Profile  
 
 Post subject: Re: session.list() outputs Entity list with same values
PostPosted: Thu Dec 24, 2009 12:12 am 
Newbie

Joined: Wed Aug 06, 2008 2:18 pm
Posts: 5
I have also tried the following with the same result:

Code:
Criteria criteria = session.createCriteria(TestModel.class);
criteria.add(Expression.eq("userId", userId));
criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
List critList = criteria.list();


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.