Hibernate version:
Hibernate Annotations 3.2.0.CR1
Hibernate 3.2 cr2
Name and version of the database you are using:
MySQL 5.0.24-standard
Hi,
When I'm using @OneToMany(fetch = FetchType.EAGER) the rows in my parent table are doubling when i fetch them.
To specify more clearly I have made an example using almost the same code as in the documentation with Troop and Soldier. The code I use can be found at
http://folk.ntnu.no/erikaxel/hibernate/ There I also have the listing of the tables I am using.
The point of interest is in Troop.java:
Code:
@OneToMany(mappedBy = "troop", cascade = {CascadeType.REMOVE}, fetch = FetchType.EAGER)
public List<Soldier> getSoldiers() {
return soldiers;
}
When I try to list all Troops with:
Code:
Session session = sessionFactory.openSession();
Transaction tx;
tx = session.beginTransaction();
List<Troop>list = session.createCriteria(Troop.class).list();
for(Troop troop : list)
System.out.println("Troop id:" + troop.getId());
tx.commit();
I get the following output
Troop id:1
Troop id:2
Troop id:2
Troop id:3
when I am using fetch = FetchType.EAGER as specified above. If I remove that but keep everything else I get
Troop id:1
Troop id:2
Troop id:3
as expected.
In the tables troop 1 has 1 soldier, troop 2 has 2 soldiers and troop 3 has 0 soldiers.
I have tried to search the forums and the JIRA but haven't found anything. To me this looks like a bug, but I thought I would post it here first in case I'm wrong. If this is wanted behaviour, please let me know.
-- Erik Axel