-->
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.  [ 2 posts ] 
Author Message
 Post subject: Null Elements in List or Array
PostPosted: Wed Sep 29, 2004 4:05 am 
Beginner
Beginner

Joined: Fri Nov 21, 2003 4:50 am
Posts: 23
Hi,

I found nothing about null elements in a list and how hibernate maps them. In a test case hibernate just ignores them, so a list with one null element is saved as a null. Or a list with some null values at the end of the list, the size of the list after saving it is smaller than before. Null values with an array are also ignored, so a saved array is smaller in length than it should be. Is there a solution (besides from a accessor which masks null values)?

Armin


Top
 Profile  
 
 Post subject: Re: Null Elements in List or Array
PostPosted: Wed Sep 29, 2004 5:22 am 
Beginner
Beginner

Joined: Fri Nov 21, 2003 4:50 am
Posts: 23
Armin wrote:
I found nothing about null elements in a list and how hibernate maps them. In a test case hibernate just ignores them, so a list with one null element is saved as a null. Or a list with some null values at the end of the list, the size of the list after saving it is smaller than before. Null values with an array are also ignored, so a saved array is smaller in length than it should be. Is there a solution (besides from a accessor which masks null values)?


I digged in the source code and it seems that there is a simple fix for this problem:

in net.sf.hibernate.collection.List use the following entryExists method.

Code:
public boolean entryExists(Object entry, int i) {
    if ( entry==null ) {
        return  i==list.size()-1;
    } else {
        return true;
    }
}


it writes a null value if the last element in the list ist null. So at most on null value is written. The same approach works with ArrayHolder, Bag,...

I don't know if there are side effects or if the current behaviour is wanted. In our project we need a way to load the state of an array/list with null elements and a mask/unmask accessor inhibits a foreign key relation![/list]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.