@Entity
@Table(name="student")
public class Student
@Id
private Integer id;
private String name;
private Integer count;
我要分配给
count
count = SELECT COUNT(*) FROM people
如何使用 JpaRepository 将结果:SELECT COUNT(*) FROM people
分配给 Integer count?
最佳答案
@Formula
帮助您在 Hibernate
中创建自己的公式。
@Entity
@Table(name="student")
public class Student
@Id
private Integer id;
private String name;
@Formula("(SELECT COUNT(*) FROM people)") // people is table name not entity
private Integer count;
关于java - 使用自定义查询(子查询) hibernate 额外列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40281774/