-->
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: PersistentMap does not read records which have NULL
PostPosted: Fri Oct 23, 2009 5:42 am 
Newbie

Joined: Thu Oct 22, 2009 2:57 am
Posts: 1
Hi,

I am using Hibernate 3.2.3 along with springframework and currently I am encountering a production issue.

I have a mapping in which one of the item is a <map> this typically is mapped to a table which has a PK (composite) and one varchar field.

Code:
<map name="sectionTitles" table="BGR_SECTIONS"
            lazy="false" >
            <key column="ITEM_ID" />
            <map-key type="string" column="SECTN_NO" />
            <element type="string" column="SECTN_TITL" />
</map>


There is some data migrated to this table and the SECTN_TITL can be NULL. What I have observed is, hibernate is not reading the rows which has NULL in SECTN_TITL, and on further investigation I found the below code snippet in PersistentMap.readForm that really prohibits reading NULL elements into the Map.

Code:
   public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
   throws HibernateException, SQLException {
      Object element = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() );
      Object index = persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() );
      if ( element!=null ) map.put(index, element);
      return element;
   }



If "IF" block highlighted in the above code snippet prohibits reading the NULL element therefore, I am not able to read the rows that contain NULL in the non-primary key field.

When I try to save a non-NULL value for the same PK, I am getting a ConstraintViolationException. In order to resolve this I extended the PersistentMap class, overridden the readFrom method and removed the if (element!=null) check. This has definitely fixed the issue i.e. i am now able to update the NULL values.

I have also created a JIRA ticket http://opensource.atlassian.com/project ... e/HHH-4515, but I am awaiting response from the Hibernate team.

Do you think the above modification of readFrom method is safer from all perspectives? I appreciate your views and comments.

Thanks,
Ram


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.