JPA 实体映射 SQL 函数结果到瞬态字段

JPA Entity mapping SQL Function result to transient field

不是为每个实体调用 SQL 函数 "manually",有什么方法可以将其结果映射到实体瞬态字段的 ?

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

谢谢

您应该可以使用 Hibernate 的 @Formula 注释:

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/