-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Lazy loading is retrieving objects with no data
PostPosted: Mon Nov 13, 2006 9:55 am 
Newbie

Joined: Mon Nov 13, 2006 9:16 am
Posts: 1
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.

_________________
David Pereira
http://www.jeebrasil.com.br


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.