I have a class called User and with a criteria search I make some User queries....
All users from the query where unique...nobody appeared several times.
Then I added the method
public Set<Picture> getPictures();
and all the previous queries now returned some sort of joined resultset where usernames appeared several times......
So I added:
criteria.setFetchMode("pictures", FetchMode.SELECT);
to every query and it is okay again......
BUT: I think I must be using some "wrong" Annotations...or why would Hibernate join the Picture table in a way usernames appear several times?
That's my User class:
Code:
@ManyToOne
@JoinColumn(name="uid")
public User getUser() {
return user;
}
@OneToMany (fetch=FetchType.EAGER)
// if I dont use Eager I get lazy exceptions, so I have to use it!
@JoinColumn(name="uid")
public Set<Picture> getPictures(){
return _pictures;
}
That's my Picture class:
Code:
public class Picture implements java.io.Serializable {
// Fields
private int picid;
private User user;
@ManyToOne
@JoinColumn(name="uid")
public User getUser() {
return user;
}
...