-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL equivalent for this SQL
PostPosted: Sun Feb 12, 2006 6:12 am 
Newbie

Joined: Tue Jan 31, 2006 8:00 am
Posts: 14
Hi All

I am using Hibernate version 3.0
This is the SQL query I have
**********************************
select obj.id, obj.name from obj, r_obj,r, usr
where obj.id = r_obj.id and r_obj.r_id = r.r_id
and usr.u_id='testuser'

**********************************

I have 2 rows in my obj table which i want to retrieve based on the above query.

So i tried to create this HQL equivalent of the above SQL as a named query
**********************************

<query name="objq"><![CDATA[
Select obj from Obj as obj
inner join obj.rObj as rObj
inner join rObj.role as role
inner join role.users as user
user.userId = ?]]></query>
**********************************

But the problem with the above HQL named query is its returning me only the 1st row of the obj table twice & not the 2 independent different rows which are in my obj table

Can some let me know what is wrong in this HQL



Regards


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 12, 2006 4:18 pm 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
Providing your many-to-one mapping are working between objects:

Code:
String userId = "testuser";
Query q = session.createQuery("u.role.rObj.obj FROM user u WHERE u.userId=?");
q.setString(0, userId);
List li = q.list();
Obj mObj = (Obj) li.get(0);


A wild guess at the HQL.


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