-->
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 und count
PostPosted: Tue Mar 31, 2009 7:16 am 
Newbie

Joined: Wed Sep 17, 2008 5:26 pm
Posts: 17
Ich versuche gerade die Anuzahl der Einträge in einer Tabelle zu zählen. Dazu mache ich folgende Abfrage:


Code:
q = session.createQuery("select count(*) from Foto f where f.id = :ppId");
q.setLong("ppId", ppId );
Die Anfrage wird ohne zu meckern gebaut.

Allerdings weiss ich jetzt nicht, wie ich das Ergebnis abfrage. Wenn ich z.B. folgendes mache,
Code:
q = session.createQuery("select count(*) from Foto f where f.id = :ppId");
q.setLong("ppId", ppId );
int count = q.executeUpdate();
dann wird die Exception
Code:
org.hibernate.hql.QueryExecutionRequestException: Not supported for select queries [select count(*) from testproject.client.universal.Foto f where f.id = :ppId]
geworfen.

Wie kann ich das Ergebnis erfahren?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 31, 2009 7:19 am 
Newbie

Joined: Wed Sep 17, 2008 5:26 pm
Posts: 17
Ach wie blöd, ich habs rausgefunden:

Code:
q = session.createQuery("select count(*) from Foto f where f.id = :ppId");
q.setLong("ppId", ppId );
long count = ((Long) q.uniqueResult()).longValue();


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.