-->
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: Get Count of Users unread Messages? [one2many]
PostPosted: Sat Jun 03, 2006 3:31 pm 
Newbie

Joined: Fri Nov 04, 2005 5:40 pm
Posts: 16
Hey,

I would like to check, how many unread messages an user has.

I have two tables, Users and Messages, User has a one to many mapping to Messages.

Alright not to check how many unread messages an User has i do the following HQL:

Code:
hql="select count(usr.messages) from Users usr where usr.username = :username and usr.messages.read=0";


but that doesnt work :(

Do you have an Idea how i could solve my problem (even if there is no such user it should return a number - 0 in that case)


Thanx for reading,
virtually yours


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 04, 2006 5:23 am 
Newbie

Joined: Wed Oct 06, 2004 2:49 am
Posts: 12
Next time please include the stacktrace. If you have mapped the association bi-directionely and you probably want that (http://www.hibernate.org/hib_docs/v3/re ... hild-bidir) then you could use:

select count(*) from Message m where m.user.name = :username and m.read=0

or even better if you have a reference to the user

select count(*) from Message m where m.user = :user and m.read=0


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.