For example we have simple class:
@Entity
@Table(name = "REQUESTS")
public class Request {
@Id
@GeneratedValue
public Long id;
@ManyToOne
@JoinColumn(name = "USER_ID", nullable = false)
public User user;
}
And there are several rows (e.g. <N> rows) with "USER_ID = null" in table "REQUESTS". Number of rows with not null "USER_ID" is <L> (e.g.) In this case:
Criteria criteria = session.createCriteria(Request.class);
criteria.setProjection(Projections.rowCount());
Number result = (Number) criteria.uniqueResult();
// result == N+L
and
Criteria criteria = session.createCriteria(Request.class);
List list = criteria.list();
// list.size() == L !!!
i.e. rowCount > actual list size.
|