We have:
@Entity public class Project { // Task is an abstract superclass, with multiple subclasses. @ManyToMany(fetchType=EAGER) private Set<Task> tasks; // Milestone is a subclass of Task public Milestone getMilestone() { for(Task task: getTasks()) { if(task.getType() == MILESTONE) { return (Milestone)task; } return null; } }
With eager load, we expect the return of getTasks() (line 9) to be a collection with non-proxy Tasks. However, the cast fails sometimes, not every time. The task (line 11) is a proxy, according to the stack trace.
We have looked at the sql that hibernate uses to drive a query. We see it joining the Project and Task tables. So, this verifies the eager fetch occurs. Would hibernate ALWAYS populate the tasks collection with the fetched data? Under what condition would the entries in tasks remain proxies?