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