-->
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.  [ 5 posts ] 
Author Message
 Post subject: Getting repeated objects when creating a criteria
PostPosted: Wed Jul 02, 2008 8:52 am 
Beginner
Beginner

Joined: Wed Apr 23, 2008 2:00 pm
Posts: 20
Hello,
When executing a criteria i'm getting repeated object. The criteria is:

List results = session.createCriteria(MyClass.class)
.add(Expression.eq("attr1", attr1))
.add(Expression.eq("attr2", attr2))
.list();

And the hbm.xml file for MyClass is:

<hibernate-mapping package="pachage">
<class name="MyClass" table="TABLE" >
<id name="attr1" column="ATTR1"/>
<property name="attr2" column="ATTR2" />
</class>
</hibernate-mapping>

On the other hand, if i do the query like this :
String sql_query = "select mc.attr1, mc.attr2 from MyClass mc" +
"where attr1='" + attr1 +
"' and attr2='" + attr2 +"'" ;
List list = session.createQuery(sql_query).list();

Does anybody knows why ?
Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 11:12 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
What about popping the results into a Set, rather than a List. A Set will not allow duplicates.

A sneaky solution, but it will work.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Can u explain this in detail
PostPosted: Fri Jul 04, 2008 12:09 pm 
Newbie

Joined: Wed Jul 02, 2008 10:39 pm
Posts: 6
Location: Hyderabad
Can u explain this in detail

_________________
Regards,
Racha Satish Kumar,
Visit Me Here!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 1:37 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Is that your complete mapping or do you have some collection marked with an outer join? What's the sql that gets generated?

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 5:14 pm 
Beginner
Beginner

Joined: Wed Apr 23, 2008 2:00 pm
Posts: 20
Cameron : i don't think it's gonna work. I want to retrieve all my records and the thing is that with criteria i'm having only the first record duplicated many times. But if i do it with the "createQuery" i'm getting all my records...
So i don't think that popping the results in a set will work...

VampBoy : yes that's the only mapping, it's just a simple query in one table.

The query produced by hibernate is the same in both cases.. so i imagine it's something wrong with my hibernate configuration...

Any way thank you both very much !


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