[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2235) Support for null map-keys in <map> mappings

Ulf gohde (JIRA) noreply at atlassian.com
Wed Jun 13 12:39:04 EDT 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_27235 ] 

Ulf gohde commented on HHH-2235:
--------------------------------

I don't agree with this statement. You don't have to have a primary key at all, instead you can use a UNIQUE CONSTRAINT and all databases support null values in a UNIQUE CONSTRAINT.
Imagine a table like
DOC_TYPE, STATE, WATERMARK; unique constraint(DOC_TYPE, STATE)
to specify watermarks to imprinted in certain document. for some document types you want to be able to configure the watermarks based possibele states of the document, for other types you just want one watermark independent of the state. In that situation it makes perfect sense to have null in your unique constraint. Otherwise you have to come up with a weird "reserved" state and all your code has to be aware of that "special" value.

When I define the key in hibernate based on this unique constraint, I am getting a null object back when querying with "where doctype='xyz' and state is null".

> Support for null map-keys in <map> mappings
> -------------------------------------------
>
>                 Key: HHH-2235
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2235
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.0.ga
>            Reporter: Igor Lobanov
>            Priority: Minor
>
> I'm not sure if I should file it as a bug.
> Hibernate requires index column for <map> mappings to be not null. This is required by the code in AbstractCollectionPersister#readIndex(...), which raises exception if index column is null. However, when I override collection persister and force readIndex method to return null, everything seems to work fine. Hibernate allows me to work with maps using null value as a key. Though I havn't tested it extensivly yet.
> What is the reason for disallowing null values as a keys? If there are possible complicated error conditions, then this issue is a feature request for null-values support for <map> mappings. If there are no errors possible, then constraining such behavior is probably wrong. 

-- 
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