-->
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.  [ 6 posts ] 
Author Message
 Post subject: same objects in result
PostPosted: Tue Jun 14, 2005 12:14 pm 
Newbie

Joined: Mon May 30, 2005 4:26 am
Posts: 4
Hi,

I am running a simple query on db2 table and getting result list of objects.
But the problem is the result list contains same object i.e, the first result row from the table. I don't understand what is the reason for this issue.
The same query fetches the right result from the editor..DB2 command center.

Query :
strQry = " FROM table A WHERE A.Num = :paramNum ORDER BY A.pNum, A.Name";

begin();
session = getSession();
Query qry1 = session.createQuery(strQry);
qry1.setParameter("paramNum",varNum);
java.util.List rs1 = qry1.list();
Debug.println("in rs1 size "+rs1.size());

Here I get the rs1.size() as 15 but it has the same object for entire list.

Please let me know if I have to make changes in configuration or anything wrong with my code itself.

Hibernate version is 2.

Thanks,
Mohan


Top
 Profile  
 
 Post subject: Re: same objects in result
PostPosted: Tue Jun 14, 2005 2:16 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Mohan wrote:
Hi,

I am running a simple query on db2 table and getting result list of objects.
But the problem is the result list contains same object i.e, the first result row from the table. I don't understand what is the reason for this issue.
The same query fetches the right result from the editor..DB2 command center.

Query :
strQry = " FROM table A WHERE A.Num = :paramNum ORDER BY A.pNum, A.Name";

begin();
session = getSession();
Query qry1 = session.createQuery(strQry);
qry1.setParameter("paramNum",varNum);
java.util.List rs1 = qry1.list();
Debug.println("in rs1 size "+rs1.size());

Here I get the rs1.size() as 15 but it has the same object for entire list.

Please let me know if I have to make changes in configuration or anything wrong with my code itself.

Hibernate version is 2.

Thanks,
Mohan


This can sometimes happen if your Object A has a relationship to other objects which is resulting in a join. Look at all of the SQL being executed by hibernate. You can get the correct results by adding the returned list to a java.util.Set.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 3:06 pm 
Newbie

Joined: Mon May 30, 2005 4:26 am
Posts: 4
Thanks for your reply. But I have a doubt, how come the problem will be resolved by adding the result list to Set as I already got the result list with same objects, which should be of different objects of 15 as I mentioned in my query.


Yes, there are queries which are using the same table but they are different. Can I do something to avoid this problem.

Please clarify.

Rgds,
Mohan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 3:08 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Mohan wrote:
Thanks for your reply. But I have a doubt, how come the problem will be resolved by adding the result list to Set as I already got the result list with same objects, which should be of different objects of 15 as I mentioned in my query.


Yes, there are queries which are using the same table but they are different. Can I do something to avoid this problem.

Please clarify.

Rgds,
Mohan


I think I misunderstood your problem. Are you expecting 15 different results and getting 15 copies of the same object, or expecting 1 result and getting 15 copies of the same object ?

My answer was for the 2nd case and adding them to a Set would result in one object since Sets don't allow duplicate objects.

I would have to see more of what you're doing for the first case.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 10:26 pm 
Newbie

Joined: Mon Jun 13, 2005 3:36 am
Posts: 4
pksiv wrote:
Mohan wrote:
Thanks for your reply. But I have a doubt, how come the problem will be resolved by adding the result list to Set as I already got the result list with same objects, which should be of different objects of 15 as I mentioned in my query.


Yes, there are queries which are using the same table but they are different. Can I do something to avoid this problem.

Please clarify.

Rgds,
Mohan


I think I misunderstood your problem. Are you expecting 15 different results and getting 15 copies of the same object, or expecting 1 result and getting 15 copies of the same object ?

My answer was for the 2nd case and adding them to a Set would result in one object since Sets don't allow duplicate objects.

I would have to see more of what you're doing for the first case.


I suppose s/he is on first case, where I am also suffering from this problem. Appreciate if pksiv or anyone could post the solution here.


Top
 Profile  
 
 Post subject: resolved
PostPosted: Wed Jun 15, 2005 2:21 pm 
Newbie

Joined: Mon May 30, 2005 4:26 am
Posts: 4
Hi,

The problem got resolved. But still I don't know the exact reason for this issue. I tried the following:

My query earlier was not having 'SELECT CLAUSE'. It was like ' From ...".
Now I tried with complete column names with SELECT..ie complete query.

The issue got resolved. I got correct data witout any redundant objects.

Thanks,
Mohan


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