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?

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Be aware that the value might be outdated if the 2nd level cache is enabled for the entity!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.