I have some entities as below
@Entity
public class Contact {
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "contact")
private Set<ContactDetails> details = new HashSet<>();
}
@Entity
public class ContactDetails {
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
private Contact contact;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "contact_details_values", joinColumn = @JoinColumn(name = "contact_detail_id"))
@Column(name = "value")
private Set<String> values = new HashSet<String>();
}
and I have a method that selects range of Contacts with DetachedCriteria as below:
public List<Contact> getContactsByRange(int start, int length) {
DetachedCriteria criteria = DetachedCriteria.forClass(Contact.class);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
Criteria executableCriteria = criteria.getExecutableCriteria(currentSession);
executableCriteria.setFirstResult(start);
executableCriteria.setMaxResults(length);
return executableCriteria.list();
}
The problem is when I call method with 0 and 10 it will return all contacts in the database, but when I call it with 0 and 1 it will return first contact in database with its first detail value and if I call it with 1 and 1 it will return first contact in database with its second detail value.