Hibernate 如何将函数执行的结果属性添加到数据对象

Hibernate 如何将函数执行的结果属性添加到数据对象,hibernate,jpa,annotations,Hibernate,Jpa,Annotations,我在数据库中有一个表和一个函数,该函数接受表的id并返回一些数字,例如(我使用Oracle语法,但我相信RDMS在这种情况下并不重要) 在hibernate数据对象类中,我想添加一个保存函数执行结果的属性。使用注释的正确方法是什么 @javax.persistence.Table(name = "test1", schema = "test", catalog = "") @Entity public class Test1Entity { private int test1Id;

我在数据库中有一个表和一个函数,该函数接受表的id并返回一些数字,例如(我使用Oracle语法,但我相信RDMS在这种情况下并不重要)

在hibernate数据对象类中,我想添加一个保存函数执行结果的属性。使用注释的正确方法是什么

@javax.persistence.Table(name = "test1", schema = "test", catalog = "")
@Entity
public class Test1Entity
{
      private int test1Id;
      @Column(name = "test1_id", nullable = false, insertable = true, 
      updatable = true, length = 22, precision = 0)
      @Id
      //get/set
      ...

      // is it possible to use annotations, 
      // so it will call a function to populate this field ?
      private BigDecimal test_num; 
}
我正在考虑创建命名本机查询,类似于
从test1a中选择a.test1id、a.val、getNum(a.test1id)作为testnum,其中a.test1id=:param\u test1id
,但这意味着我无法使用
会话.get
从数据库读取对象

谢谢。

请使用以下选项:

@Formula( "getNum(test1_id)" )
private BigDecimal test_num; 
@Formula( "getNum(test1_id)" )
private BigDecimal test_num;