thank a lot for view my question.
I have a 2 Entities with relationship: one-to-many. They are "staff" and "role".(One Staff has many Role)
This is "Role" in Staff :
@OneToMany(cascade = CascadeType.ALL, mappedBy = "staffId", fetch = FetchType.EAGER)
private Collection<Role> roleCollection;
And I tried to select a specify numbers of Staff with codes:
Criteria crit = session.createCriteria(Staff.class);
crit.setFirstResult(0);
crit.setMaxResults(20);
crit.setFetchMode("id", FetchMode.SELECT); // This solution in SOF but it not work
crit.addOrder(Order.asc("id"));
crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
result = crit.list();
I known my problem.
- Criteria.DISTINCT_ROOT_ENTITY
remove duplicate entity after getting data from Database
- But setMaxResults(20);
calculate number of results include duplicate result.
So, my List of result less than my maxResult()
I tried some solutions was solved on SOF, but all of them failed. I think because my config in entity class: FetchType.EAGER
but i dont want to change it to LAZY
can you help me to solve it?