-->
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.  [ 6 posts ] 
Author Message
 Post subject: Calculated field for collection size
PostPosted: Tue Sep 23, 2003 8:01 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
I have a master/details relationship. Is it possible in the master to have a calculated property that corresponds to the number of details in the relationship.
Something like "select count(ID) from details where master_id=?" (I don't know if it is possible to have some parameters in the formula)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 8:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
If the collection is lazy and you don't want to initialize it, then use a filter. Otherwise, just use its size()...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 8:40 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
I want to have a getNumberOfDetails() in my master class that gives me the number of details without loading the details collection. What embarrass me with the filter is that it puts some hibernate code into my class.
I am wondering why the "size" method of the collection proxy does not use a filter in the background to avoid loading the collection when I just want the size.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 8:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
I am wondering why the "size" method of the collection proxy does not use a filter in the background to avoid loading the collection when I just want the size


Because it is easy enough to do from application code...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 9:01 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Ok but you are agree with me that I have to put some Hibernate code into my Master object, aren't you ?
I'am agree with you that it is easy to do in the application but it is not as 'transparent' as the 'size".


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 9:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
Ok but you are agree with me that I have to put some Hibernate code into my Master object, aren't you ?


depends how you have set up your architecture. Sounds like just another argument for DAOs.

I have some "persistence-related" code in my domain objects, but because it all happens through DAO interfaces, there is nothing Hibernate specific in any of my domain entities....


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