-->
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: Hibernate mapping returning Set & null intermittently
PostPosted: Sun Mar 02, 2008 2:18 pm 
Newbie

Joined: Thu Feb 28, 2008 12:35 pm
Posts: 15
hi all,

I need help in understanding how the collection mapping works with hibernate.

I have this sample mapping in my application.

Mapping for class Employee

private Set departments; //Note here i havent given initialized to any value..

public Set getDepartments() {
return departments;
}

public void setDepartments(Set departments) {
this.departments = departments;
}

In my Dao class when i use employee.getDepartments().size() , this returns 0 sometimes for new employee and sometimes i am getting NullPointerException with employee.getDepartments() for the new employee.

I dnt understand this behavior of hibernate, how i am able to get the departments Set sometimes & null at rare times.

your response is awaited..

thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 03, 2008 4:32 am 
Regular
Regular

Joined: Mon Aug 06, 2007 10:49 am
Posts: 67
Location: Banska Bystrica, Slovakia
should be this:
if u save new employee with department=null after save, still departement == null, but if u retrieve employee from db departement will be empty set.

or maybe you sometime set departments with empty set and sometimes not


Top
 Profile  
 
 Post subject: Hibernate mapping returning Set & null intermittently
PostPosted: Mon Mar 03, 2008 9:19 am 
Newbie

Joined: Thu Feb 28, 2008 12:35 pm
Posts: 15
Its like in the Employee class my declaration as earlier shown is not initialized. And when i save the Employee i wont bother about the department mapping also.

But when i query employee.getDepartments() i am able to get Collection with size = 0 but sometimes (say 1 out 6) times it gives null Collection.

what may b da reason?


Top
 Profile  
 
 Post subject: Re: Hibernate mapping returning Set & null intermittentl
PostPosted: Wed Mar 05, 2008 8:36 am 
Regular
Regular

Joined: Mon Aug 06, 2007 10:49 am
Posts: 67
Location: Banska Bystrica, Slovakia
bourne2hib wrote:
But when i query employee.getDepartments() i am able to get Collection with size = 0 but sometimes (say 1 out 6) times it gives null Collection.

what may b da reason?


propably 1 out 6 means that u are doing it little different than other cases, try to simulate it in test


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.