Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java, hibernate: mapping property with a query

I have an entity with a property "quantity", this value is not a table field but is dynamically calculated with an hql query.

So, is possibile to add this value in my entities and make hibernate calculate it when I load my entities?

like image 745
blow Avatar asked Feb 06 '11 11:02

blow


1 Answers

You an use formula annotation. for example:

@Formula("(select min(o.creation_date) from Orders o where o.customer_id = id)")
private Date firstOrderDate;

See this post: Calculated property with JPA / Hibernate

Se also Hibernate tutorial: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-column

like image 80
danny.lesnik Avatar answered Sep 19 '22 11:09

danny.lesnik