I am using Hibernate 3.3.1.GA
I have three entities
One User has many Answers. Every Answer has zero or one Couple
I get the User ok.
If I get the user.getAnswers(). It starts fetching the Couples and other objects. I don't want that. I only want the Answers.
This is the relevant code.
Code:
@Entity
public class User {
...
@OneToMany(mappedBy="user")
@JoinColumn(name="userId")
@Cascade(value = { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
@LazyCollection(LazyCollectionOption.TRUE)
public Set<Answer> getAnswers() {
if (answers == null)
answers = new HashSet<Answer>();
return answers;
}
...
}
Code:
@Entity
public class Answer {
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="coupleId")
public Couple getCouple() {
return couple;
}
...
Code:
@Entity
public class Couple {
...
}
I have also tried with @LazyToOne(LazyToOneOption.PROXY) @Fetch(FetchMode.SELECT)
When I do user.getAnswers() these queries are generated (edited for clarity)
Code:
select * from Answer answers0_ where answers0_.userId=?
select *
from Couple couple0_ inner join User user1_ on couple0_.manId=user1_.user Id
left outer join Photo photo2_ on user1_.approvedPrimaryPhotoId=photo2_.photoId
left outer join Invitation invitation3_ on user1_.invitationId=invitation3_.invitationId
left outer join Country country4_ on user1_.countryCode=country4_.countryId
left outer join PostalZone postalzone5_ on user1_.myPostalCodeId=postalzone5_.postalZoneId
inner join User user6_ on couple0_.womanId=user6_.userId
where couple0_.coupleId=?
// repeated and repeated many times.
What I want to do is just to get the Answers without getting the Couples.