Hi,
I have an entity, let's call it XRequest, which has a member called RequestgroupXConfig (which is actually a Many-To-Many association table of two IDs, but that doesnt matter).
Code:
@Entity
class XRequest {
// other members, stuff...
@ManyToOne
@Basic(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name="group_id", referencedColumnName="group_id"),
@JoinColumn(name="config_id", referencedColumnName="config_id")
})
private RequestgroupXconfig requestgroupXconfig;
}
Then, I use an HQL statement (following) to query XRequest with a bunch of joins to other tables.
Code:
Query q = em.createQuery("SELECT DISTINCT e, rg, sc, svt, srt, st
FROM XRequest e
inner join fetch e.requestgroup rg
inner join fetch e.someconfig sc
inner join fetch e.someversionthing svt
inner join fetch svt.somereleasething srt
inner join fetch srt.something st
WHERE e.something != 'whatever'
order by e.bullshit");
List li = q.getResultList();
Now, this query is executed just fine. But while executing getResultList(), another query happens to pop up on my radar: a query to requestgroupXconfig (which actually is a many-to-many id-association table of "requestgroup" and "someconfig"; one group may have many configs or many groups one config or many groups many configs). I am not using requestgroupXconfig though, not joining it, and I annotated it as lazy fetching - why on earth is that query executed?
(Don't ask me why the requestgroupXconfig is there - it just has to be; not my specs. I can't remove it, I'm not allowed to.)
Thanks,
Chris