-->
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: How to rewrite my Hibernate query for the Plain Sql below.
PostPosted: Tue Aug 28, 2007 7:41 am 
Newbie

Joined: Tue Oct 31, 2006 7:09 am
Posts: 4
How to write in Hibernate perspective for the following sql query,


select * from PList where owner = "user" or groupId in ("group 1","group 2",group3" ) order by owner ,group;


I have table with

Quote:
Plist with column (id,type,name,owner,bid,createdate,groupId)
and
Group with column (groupId,name,desc,createdate,createby).
Here groupId is Foreign Key.


I tried something as,
Code:

String queryString = "from Plist play where play.owner = :key " +
        " and play.type = :str " + "and gprid =Group.groupId" +
        " and play.bid = :brn order by owner,groupId;

queryObject = getSession().createQuery(queryString);
queryObject.setLong("brn", bran);
queryObject.setParameterList("gprid", (Collection) groupIds);
queryObject.setString("key", user);
queryObject.setString("str", type);


I will pass to this query string with values ( bran = 1 ,groupIds = [1,2,3],user = srins,type='t').


How to rewrite my query according to the select statement which i have mentioned above.

ie,

select * from PList where owner = "user" or groupId in ("group 1","group 2",group3" ) order by owner ,groupId;

Can anyone help me in this regard.

Thanks,
srins.


Top
 Profile  
 
 Post subject: Try this :
PostPosted: Tue Aug 28, 2007 11:58 am 
Newbie

Joined: Thu Jul 12, 2007 5:33 pm
Posts: 5
String queryString = "select play from Plist as play , Group as group where play.owner = :key " +
" and play.type = :str " + "and play.grpid =group.groupId" +
" and group.groupId in (:groupIds) "
" and play.bid = :brn order by owner, paly.grpId;


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.