[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-772) null in maps are handled inconsistently

Kai Kunstmann (JIRA) noreply at atlassian.com
Tue Apr 5 14:20:01 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-772?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=41974#action_41974 ] 

Kai Kunstmann commented on HHH-772:
-----------------------------------

After long thinking about it, I realize now how this "feature request" of allowing null-values in a map is hard to implement reasonably. I'm writing here to help other people understand the problem and maybe introduce another idea for a solution:

It is true, that a {{java.util.Map}} is defined in terms of a {{java.util.Set}} of {{java.util.Map.Entry}} with no entry having a key equal to any other entry's key in the same entry-set, and that people want to persist every entry of that set no matter if its missing a value, i.e. they want to persist the _absence of a value_ while not giving up the relation between key and map-owner -- especially with a {{<map-key-many-to-many>}}. There doubtlessly are use-cases for this, and it truly is a reasonable request -- if you look at it from the Java point-of-view. I would like to do that, too, instead of coding complicated workarounds. However, with a simple {{<one-to-many>}} mapping in place of the map-value (even so with a {{<composite-element>}}) it becomes impossible to express the desired _absence of value_, since the key would have to go into the same row as the missing entity (or component), which means having an empty row with nothing in it -- especially no id -- but a key and a reference to the owner to express the _absence of an entity_. This is obviously absurd, and in my opinion the only true reason why this issue _won't fix_. With a {{<one-to-many>}} mapping the value of a map-entry essentially _is_ the entry, which is likewise questionable.

A solution to this predicament could be the introduction of an {{<idmap>}} with a surrogate {{<collection-id>}}, which obviously cannot contain a {{<one-to-many>}} mapping but could be made capable of expressing _absence of value_ by the requirement of {{table}} attribute and a {{<many-to-many>}}, {{<many-to-any>}}, {{<element>}} or {{<composite-element>}} mapping as with the {{<idbag>}} to serve as a standalone entry-row with an explicit id. There certainly are other considerations to make -- it's just an idea...


> null in maps are handled inconsistently
> ---------------------------------------
>
>                 Key: HHH-772
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-772
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: core
>            Reporter: Max Rydahl Andersen
>             Fix For: 3.1 beta 1
>
>
> regarding case 00004729.
> group.getUsers().put("something", null);
> Does not result in any insert.
> Inserting "something", null manually into the underlying table and
> when hibernate reads the map will have "something"->null in the map.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list