Silent exclusion of null-valued map entry
Description
Activity

Brett MeyerJuly 8, 2014 at 3:11 PM
Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!

Brett MeyerApril 7, 2014 at 5:42 PM
In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.
If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.
Thank you!

Eric StadtherrFebruary 6, 2013 at 9:37 PM
This bug has caused pain for my project as well. Hibernate seems to be treating a null-valued mapping in a basic element collection (i.e. a Map<String,String>) as no mapping at all, which is obviously incorrect.
Some of the discussions in other related issues (such as HHH-772, which is marked as closed:fixed for some reason even though the bug is still very much present in Hibernate 4.1.9) have suggested that having null values in Map collections is invalid, and therefore this isn't a bug. Having a null value for a map is perfectly valid, and is fully supported by the Java Map types. Semantically, the presence of a value with a null value association is much different than the value being completely absent from the map.
The Hibernate developers (or some vocal subset of them) might not understand why an application designer might choose an object model that is structured this way, but that is irrelevant. Hibernate's purpose as an ORM tool is to map an object model to a relational schema, not to make subjective determinations about an application's object model. In this case, the mapping can be fully supported by NULL values in the relational table, so Hibernate should not get in the way of capturing the persistent state of the application's model.
Please let me know if there's anything else I can provide as far as support for getting this bug finally fixed.

Andreas DeppischJune 18, 2010 at 7:08 AM
I know this kind of issue was discussed a lot. But from my point of view I agree that this is a bug. I read the arguments from Gavin from issue HHH-772, but I disagree with him. My use case is a map with key value pairs whereas the total map is an identifier. For that use case a map with a key and value null
is different to a map with a removed key. A comparison from a map written to the database and reading the same map fails always.
Not expecting this issue, now it is a big effort to change my datamodel and rework the mapping in order to get what I need because the software is already running on several customer projects.
Please Gavin rethink your arguments. Maybe there is a compromise to set the behaviour with annotations as already suggested.
Details
Assignee
UnassignedUnassignedReporter
Tsering ShresthaTsering ShresthaComponents
Affects versions
Priority
Major
Details
Details
Assignee
Reporter

<class name="Product">
<id name="id">
<generator class="native"/>
</id>
<map name="sellingPrice">
<key column="PRODUCT" not-null="true" foreign-key="FK_SP_PRODUCT"/>
<map-key type="string" column="model" not-null="true"/>
<element type="double" column="price" not-null="false"/>
</map>
</class>
Product product = new Product();
Product.getSellingPrice().put("XL",null);
Product.getSellingPrice().put("L", 34.90);
session.save(product)
Gives the following SQL:
insert into PRODUCT (id) values (null)
call identity()
insert into SELLINGPRICE (PRODUCT, MODEL, PRICE) values (?, ?, ?)
And the SELLINGPRICE table indeed only has one row. Why does Hibernately silently remove my null-valued entry? I would either want it to be able to save the entry or raise an exception that it cannot.
Report this post