The problem is not in the eager-fetch. There has to be something else in your mapping. Here is my equivalent test-case using annotations (which should not be the important point):
Code:
@Entity
public class Customer {
...
@OneToMany(fetch=FetchType.EAGER)
@JoinColumn(name="customer_id")
public Set<Contact> getContacts() {
return contacts;
}
...
}
In my persistence.xml:
Code:
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.default_batch_fetch_size" value="16" />
<property name="hibernate.jdbc.batch_size" value="2" />
My test-statement:
Code:
em.createQuery("from Customer").getResultList();
And here is my generated SQL:
Quote:
Hibernate:
select
customer0_.id as id1_,
customer0_.someProperty as someProp2_1_,
customer0_.someProperty2 as someProp3_1_
from
Customer customer0_
Hibernate:
select
contacts0_.customer_id as customer3_1_,
contacts0_.id as id1_,
contacts0_.id as id0_0_,
contacts0_.someProperty as someProp2_0_0_
from
Contact contacts0_
where
contacts0_.customer_id in (
?, ?
)
As you can see, batch-fetching works with eager collections in this case, maybe you can find a difference to your case, besides using JPA and Annotations.