Here is my entity models.
@Entity
@Table(name = "Folder")
public class Folder implements Serializable{
private User user;
//unidirectional association
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "AssignedToUserID" ,nullable=true)
public User getUser() {
return user;
}
}
@Entity
@Table(name = "User")
public class User implements Serializable{
@Id
@Column(name = "UserID")
public Integer getUserId() {
return this.userId;
}
}
Basically i want retrieve all folders together whether the folder has assigned user or not.
And here is my HQL query:
*SELECT folder from Folder folder inner join fetch folder.user user*
SQL generated By hibnermate:
select
folder0_.FolderID ,
folder0_.FolderName ,
folder0_.AssignedToUserID ,
user_0.UserID ,
user_0.UserName
from
Folder folder0_
left outer join
User user_0
on folder0_.AssignedToUserID=user_0.UserID
I wanted to eagerly load all associated entities, I really wanted to avoid the other select statements because it hurts performance and i am retrieving around 500k of records.
I am expecting that hibernate will return null instance when it sees that AssignedToUserID is NULL. But unfortunately it throws EntityNotFoundException though.
Am i missing something here? Any suggestion is appreciated.