Calculated property with JPA / Hibernate

Posted by Francois on Stack Overflow See other posts from Stack Overflow or by Francois
Published on 2010-06-06T23:14:22Z Indexed on 2010/06/06 23:22 UTC
Read the original article Hit count: 362

Filed under:
|

My Java bean has a childCount property. This property is not mapped to a database column. Instead, it should be calculated by the database with a COUNT() function operating on the join of my Java bean and its children. It would be even better if this property could be calculated on demand / "lazily", but this is not mandatory.

In the worst case scenario, I can set this bean's property with HQL or the Criteria API, but I would prefer not to.

The Hibernate @Formula annotation may help, but I could barely find any documentation.

Any help greatly appreciated. Thanks.

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about jpa