我有一个类似的实体类:
@Entity
@Table(name = "T_STUDENT")
public class Student implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private StudentId studentId;
.....
StudentId课程是:
@Embeddable
public class StudentId implements Serializable{
private static final long serialVersionUID = 1L;
@Column(name = "ID", nullable = false)
private Long id;
@Column(name = "STATE", nullable = false)
private String state;
现在我需要找到学生的数量。我这样做:
public <T> Long findCountWithFilter(Class<T> clazz, FilterCriteria filterCriteria) {
Util.checkNotNull("needs a clazz", clazz);
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<T> root = cq.from(clazz);
cq.select(cb.count(root));
return entityManager.createQuery(cq).getSingleResult();
}
我得错了结果。计数总是0.任何想法为什么?