I have two entities: User and Address. User has an "address" property:
@OneToMany (mappedBy="user", fetch=FetchType.EAGER)
public List<Adress> getAddress() {
return this.address;
}
public void setAddress(List<Adress> address) {
this.address= address;
}
The fetch type is eager as shown above.
I'm trying to use Criteria in order to get a list of Users as follows:
List<User> p=session.createCriteria(User.class).list();
Unfortunately it gets repeated users if a user has more than one address. With eager fetching turned off, it doesn't get duplicates. How can I get a list of users without repeated items using Criteria?