Class A
has a one-to-many relationship to B
. Hence, A
has an attribute collectionOfB
.
Is there any way I could map "count B" to single attribute in A
?
The purpose would be to offer a shortcut to retrieve the number of associated B
s without loading the entire collection. Sometimes all I need is the count i.e. the collection size. I know I could issue a query against the entity manager that does exactly that. However, seeing it done by the JPA provider thanks to annotations would of course be preferable.
I was able to solve my problem using Hibernate's extra-lazy mapping: http://www.frightanic.com/2010/11/21/extra-lazy-one-to-many-mapping-with-hibernate/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With