-->
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: Saving count(*) in an annotated entity
PostPosted: Thu Jul 03, 2008 1:22 am 
Newbie

Joined: Thu Jul 03, 2008 1:00 am
Posts: 1
How to specify the following request:
Code:
select count(*) from <another-table> where id = <current-id>

with an annotation in an entity? I would like to have a field called size in my entity which should have the value returned by the upper SQL request. This field is not saved in the database, so it is transient.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 1:26 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
If it's just a simple count, there's no reason why you can't just do a simple SQL query.

If there's an object mapped to the table, you could just use a from 'object' HQL query. Criteria queries always work well too, but I think simple HQL and then doing a size() method call on the returned list/collection would be sufficient.

How to do HQL and Native queries with Hibernate3:


http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=08masteringhqlandnamedqueries

Do you see any problems with that? What is the issue you are anticipating?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.