-->
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: hql Abfrage mit criteria abbilden
PostPosted: Fri Mar 20, 2009 5:52 am 
Newbie

Joined: Fri Feb 06, 2009 3:44 am
Posts: 9
Hallo,

ich möchte folgenden hql Abfrage durch die Verwendung von Criteria ersetzen:

hql = "select accessLevel.id from AccessProfile accessProfile join accessProfile.accessLevels as accessLevel where accessProfile.id='"
+ accessProfile.getId()
+ "' order by accessLevel.id asc";


Ich krieg das einfach nicht hin. Hoffe es kann mir hier wer helfen.

mfg


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 1:23 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Code:
session.createCriteria(AccessProfile.class).add(Restrictions.idEq(accessProfile.getId()).createAlias("accessLevels", "accessLevels").addOrder(Order.asc("accessLevel.id"))

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 26, 2009 5:22 am 
Newbie

Joined: Fri Feb 06, 2009 3:44 am
Posts: 9
Hallo,

erstmal danke für deinen input.

Wenn ich das so so implementiere ist die Ergebnismenge eine Liste von AccessProfile Objekten. Ich bräuchte allerdings eine Liste von accesslevel ids. Geht das überhaupt ?

mfg


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 28, 2009 9:00 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Ja das geht:
Code:
session.createCriteria(AccessProfile.class).add(Restrictions.idEq(accessProfile.getId()).createAlias("accessLevels", "accessLevels").addOrder(Order.asc("accessLevel.id")).setProjection(Projections.property("accessLevel.id"))


Du willst also nur die ids der levels eines bestimmten Profiles? Ist deine Beziehung bidirektional? Wenn ja, wäre es viel einfacher...

Rating ist willkommen. ;-)

_________________
-----------------
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.