-->
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: Pb with result of select HQL command
PostPosted: Thu Nov 03, 2005 11:33 am 
Newbie

Joined: Mon Oct 03, 2005 8:39 am
Posts: 4
Hello,

i have a pb using a simple HQL select command.

String q = "from XXX c where c.version.id = " + versionId;
List result = getDao().executeQuery(q);

this returns me always only 1 element in the result list, even if in my table i have multiples lines where the version id = the parameter !?...


If i use the following syntax instead :

String q = "from XXX where VERSION_ID = " + versionId;
List result = getDao().executeQuery(q);

(where VERSION_ID is the name of the SQL table column)
this time it returns me correctly all the lines where the version id equals my parameter !

please, can someone explain to me why these two requests don't return the same result ???...

thank you

Stephane


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 11:53 am 
Regular
Regular

Joined: Mon Oct 06, 2003 7:17 am
Posts: 58
Location: Switzerland
Hi Stephane

id is a reserved keyword in hql and it will always point to the id property and not to your version id

Reto


Top
 Profile  
 
 Post subject: Re: Pb with result of select HQL command
PostPosted: Thu Nov 03, 2005 11:58 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
What does this method do ? Can you show the code that is actually performing the query ?

Code:
List result = getDao().executeQuery(q);

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 12:12 pm 
Newbie

Joined: Mon Oct 03, 2005 8:39 am
Posts: 4
first of all thank you for answering me.

for Reto :
i can't see why the pb might come from the "id" as you suggest...
because in my application i have almost all objects that inherit from NamedObject, and so who have a "id" attribute that identifies them... and in the other HQL requests i make in the same way for various objects ("from XX x where x.id = myId") it seems to work correctly...

for Pksiv :
the code you asked :

public List executeQuery(String query)
{
return getHibernateTemplate().find(query);
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 12:19 pm 
Expert
Expert

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

Sorry but I don't use Spring and I'm amazed at how many problems I see posted here in regards to the getHibernateTemplate().find(query); method

The fact that it works when you specify the column name and not when you specify the property name makes me think that it's executing a SQLQuery instead of an HQL Query.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 12:27 pm 
Newbie

Joined: Mon Oct 03, 2005 8:39 am
Posts: 4
Quote:
The fact that it works when you specify the column name and not when you specify the property name makes me think that it's executing a SQLQuery instead of an HQL Query.


if it was the case, i would get an error when executing my request, or i would have none element found, isn't it ?
but in fact i have always as a result ONE element (the last element i have inserted in my database, with the id = to the parameter) !

how can i try to switch SQLQuery by HQLQuery with this HibernateTemplate.find request ?...


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.