@Entity
@Table(name="student")
public class Student
@Id
private Integer id;
private String name;
private Integer count;
我想分配给
计数
count = SELECT COUNT(*) FROM people
如何使用JpaRepository将结果:SELECT COUNT(*) FROM people
分配给整数计数?
答案 0 :(得分:5)
@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;