Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.2
Hi,
I have two entity classes that have a one-to-one relationship. This is how I have them mapped:
Code:
@Entity
public Person
{
private Student student;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "person_id")
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
}
@Entity
public Student
{
private Person person;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "person_id")
public Person getPerson()
{
return person;
}
public void setPerson(Person person)
{
this.person = person;
}
}
Whenever I perform a query involving Person, it will do a separate select to retrieve Student even though I have specified lazy fetching. This is a performance problem for me since I don't want to get Student every time.
Any ideas why this is happening and how I can make it not eager fetch the Students?
Thanks!