-->
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.  [ 4 posts ] 
Author Message
 Post subject: Help formulating a query/criteria
PostPosted: Sun Apr 05, 2009 8:44 am 
Newbie

Joined: Sun Apr 05, 2009 8:22 am
Posts: 2
I have a model/Object, aModel it has two columns/properties those two columns have the same type:

public class aModel
User origiUser
User substituteUser
...

basically a the model has two prperties of the same type, User (note that User model has property userID), and substituteUser is nullable.

now the problem is this, given a userID I would want to retrieve all aModels with the given userID. but you have to look at substituteUser first before checking origUser.

something like this.

select * from aModel where (if substitueUser is null use origUser.userID otherwise use substituteUser.userID) = :givenUserID

something like that.

I hope someone can help out..

Many thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 05, 2009 5:23 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
case-when is what you need in sql:
Code:
select * from Model where (case when substitueUser is null then origUser.userID else substituteUser.userID) = :givenUserID

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: how about using them with Criteria?
PostPosted: Mon Apr 06, 2009 9:30 pm 
Newbie

Joined: Sun Apr 05, 2009 8:22 am
Posts: 2
Thanks sir..
Thats very neat..
how about using this query with Criteria?

Thanks a lot sir..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 07, 2009 11:36 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
AFAIK it's not possible in criteria...

_________________
-----------------
Need advanced help? http://www.viada.eu


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