-->
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.  [ 3 posts ] 
Author Message
 Post subject: Frage zu Criteria
PostPosted: Wed Sep 13, 2006 4:43 am 
Newbie

Joined: Fri Sep 08, 2006 4:05 am
Posts: 5
Hi,

eine kurze Frage zu dem Gebrauch von Criteria. Unten habe ich einen Criteria Query geschrieben welches mir eine Liste von Objekten der Klasse OrgUnit zurückgibt. Ich möchte aber gerne nur eine Liste mit dem Property (LongName) von OrgUnit zurück kriegen anstelle des ganzen Objektes.

in SQL würde der query folgendermaßen aussehen
Select ou.longName from OrgUnit ou where ........


Criteria criteria = HibernateUtil.currentSession().createCriteria(OrgUnit.class);
criteria.createAlias("orgUnitDef", "ouDef");
criteria.add(Restrictions.eq("ouDef.name", type)).add(Restrictions.eq("active", new Integer(1)));

Iterator iterator = criteria.list().iterator();
TreeMap resultMap = new TreeMap();
while(iterator.hasNext()){
String name = ((OrgUnit)iterator.next()).getLongName();
resultMap.put(name, name);
}

wie kann ich das machen???


Vielen dank im vorraus
fz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 6:35 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Aus meinem Buch kopiert ;-)

Code:
      results = session.createCriteria(JavaClub3.class).setProjection(
            Projections.property("name")).setResultTransformer(
            new AliasToBeanResultTransformer(JavaClub3.class)).list();

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 6:44 am 
Newbie

Joined: Fri Sep 08, 2006 4:05 am
Posts: 5
LaLiLuna wrote:
Aus meinem Buch kopiert ;-)

Code:
      results = session.createCriteria(JavaClub3.class).setProjection(
            Projections.property("name")).setResultTransformer(
            new AliasToBeanResultTransformer(JavaClub3.class)).list();


Danke für die antwort :=)


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