16

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?

Draken
  • 3,134
  • 13
  • 34
  • 54
blow
  • 12,811
  • 24
  • 75
  • 112
  • 1
    Possible duplicate of [Calculated property with JPA / Hibernate](http://stackoverflow.com/questions/2986318/calculated-property-with-jpa-hibernate) – Draken Jan 09 '17 at 12:36

1 Answers1

28

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

Community
  • 1
  • 1
danny.lesnik
  • 18,479
  • 29
  • 135
  • 200