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: @ElementCollection of List<String> and null entries
PostPosted: Wed Jul 06, 2011 3:11 pm 
Beginner
Beginner

Joined: Thu Oct 06, 2005 7:34 pm
Posts: 20
I'm looking for some confirmation on the following behavior using Hibernate 3.6.5

I have this in an @Entity
Code:
    @ElementCollection(fetch =FetchType.EAGER, targetClass = String.class)
    @JoinTable(
        name = "UP_PORTLET_PREF_VALUES",
        joinColumns = @JoinColumn(name = "PORTLET_PREF_ID")
    )
    @IndexColumn(name = "VALUE_ORDER")
    @Lob
    @Column(name = "PREF_VALUE")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    @Fetch(FetchMode.JOIN)
    private List<String> values = new ArrayList<String>(0);


When I store a list of [null, "", null, "", null] what I get back when I go to retrieve the data is [null, "", null, ""]. Similarly if I just try to store [null] I get back an empty on retrieval. I understand that the values variable itself will never be null since an empty set and null are essentially the same thing but it seems strange that null entries at the end of my list are dropped.


Top
 Profile  
 
 Post subject: Re: @ElementCollection of List<String> and null entries
PostPosted: Wed Jul 06, 2011 3:15 pm 
Beginner
Beginner

Joined: Thu Oct 06, 2005 7:34 pm
Posts: 20
After doing a little more digging it appears that hibernate is not persisting collection rows that have null values. For example here is what gets stored in the UP_PORTLET_PREF_VALUES table for a list of [null, "", null, "", null].

Code:
PORTLET_PREF_ID,PREF_VALUE,VALUE_ORDER
104,"",1
104,"",3



It appears that by-design hibernate is not persisting a row for each null value in the List. This works if the last value is not null because the IndexColumn allows for reconstruction of the List with null entries and the List is the correct length. In the case of the last entry being null though only entries up to the last non-null entry are reconstructed due to the lack of List length data in the DB.

Is this the intended behavior?


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.