Hibernate version: 2.1.6
Mapping documents: Generated with xdoclet
Code between sessionFactory.openSession() and session.close():
<br/>Using Springframework's OpenSessionInViewInterceptor
Full stack trace of any exception that occurs:
Name and version of the database you are using: MySQL 4.0x
I have an owning object called QualificationReviewSession. It owns a collection of QualificationReviewSessionUsers -- which is just a many-to-many mapping table containing a foreign key to the QualficationReviewSession and a foreign key to an associated User.
I want to load those qualificationreviewsessions which are associated with a particular users.
list = getSession()
.createQuery(
"select new com.ccg.qualreview.support.QualificationReviewSessionInfo(qrs.id,qrs.sessionName,qrs.client.name,qrs.notes) "
+" from QualificationReviewSession qrs "
+" inner join qrs.qualificationReviewSessionUsers as users "
+" where users=:user"
+" order by qrs.client.name, qrs.sessionName asc"
)
.setEntity("user",user)
.list()
;
This works just fine. The problem comes when I use:
+" inner join fetch qrs.qualificationReviewSessionUsers as users "
For some reason Hibernate will load the correct list, and proceed to
delete from qualificationReviewSessionUsers where qualificationReviewSession = ?
(unfortunately I don't have a current show_sql output. Since I solved it by taking out the "fetch" ...)
What's going on with that? ( In know, it's a really smart question.) Since I don't really need the User to be instantiated in this query I don't really need the fetch ... it seems like a bug - it also seems that I don't really understand fetch. Comments?
|