1

我有一个实体类,如:

@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。知道为什么吗?

4

0 回答 0