Search code examples
hibernatejpahibernate-mapping

JPA Entity mapping SQL Function result to transient field


Instead of calling SQL function "manually" for every entity, is there any way to map its result to an entity transient field's ?

@XXXX(call function with param ?)
private int calculatedValue;

Thanks


Solution

  • You should be able to use Hibernate's @Formula annotation:

    https://docs.jboss.org/hibernate/orm/5.1/javadocs/org/hibernate/annotations/Formula.html

    https://thoughts-on-java.org/hibernate-tips-calculate-entity-attributes-formula/