I'm having a problem with hibernate that I've never had before. I'm using Hibernate 3.2 and Hibernate Annotations.
I have a class named Group with a Set of Itens mapped as lazy. The mapping is as follows:
Group:
Code:
@OneToMany(fetch=FetchType.LAZY, mappedBy="grupo")
private Set<Item> itens;
Item:
Code:
@ManyToOne
@JoinColumn(name="id_grupo")
private Grupo grupo;
I want to list all groups with all their items, so I ask my dao to find all the groups and then, for each group, I call group.getItens(). Something like:
Code:
Collection<Group> groups = myDao.findAll(Group.class);
for (Group group : groups) {
System.out.println(group.getName());
for (Item item : group.getItens()) {
System.out.println(item.getName());
}
}
Here, the dao's findAll code:
Code:
Criteria c = session.createCriteria(Group.class);
return c.list();
Everything is fine with the first group, but with the second and beyond, the Set of itens is coming with some objects inside (the correct number of objects) but they're with id zero e the other attributes are null.
I have no idea of what's going on... I hope someone can help.