-->
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.  [ 4 posts ] 
Author Message
 Post subject: Null when retriewing an object
PostPosted: Thu Jan 17, 2008 10:42 am 
Newbie

Joined: Thu Jan 17, 2008 10:21 am
Posts: 2
Hi , i've some problem when retriewing complex object from db:
(It's my first project with hibernate)..

i have a class Book that has a list of Items. (one to many classical mapping) .

I've no problems when i save the book , in db , i see the table corrisponding to Book having a new row and in the table corresponding to Item all the items related, and the items have FKkey IdBook corectly set.

But..
Wen i load a book by id with the following operation ..

Book book =session.load(Book.class, new Long(id));

i obtain the book properties and the list of item

List list = book.getItemList();

Item firstitem = list.get(0);

with a debugger i see that :
list contains all the items
unfortunatly firstitem = null .

Why? ??

Can someone help me ?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 11:17 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
what is inside that getItemList method of your Book class?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 11:27 am 
Newbie

Joined: Thu Jan 17, 2008 10:21 am
Posts: 2
gonzao_diaz wrote:
what is inside that getItemList method of your Book class?



Hi , i report the key methods

class Book {
Long idBook;
.... attributes


List itemList;

// methods

public List getItemList() {

return itemList;
}

...

public addItem(Item i) {
itemList.add(i);
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 12:20 pm 
Newbie

Joined: Thu Jan 17, 2008 12:14 pm
Posts: 1
What is in your setItemList method of your Book class? You only have an addItem method in your code snippet.

John


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

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.