Map of @Embeddables has values loaded only when != null

Description

Hello,

here's my setup:

where LocalizedValue is:

I create one Product assign two values for it's description (first entry is <Locale.ENGLISH, null> and the second is <Locale.GERMAN, "test">). Then I select the product from the database, and inspect the description map - the result is it only has 1 element in the map - <Locale.GERMAN, "test"> one.

I will create a test project soon.

Environment

None

Activity

Show:
Petar Tahchiev
May 10, 2017, 2:03 PM

It could be database-specific - under mysql the NULL values are stored. I haven't checked hsql though.

Gail Badner
July 21, 2017, 6:06 AM
Edited

This is expected behavior. Hibernate should not be writing null elements to the collection table. If Hibernate happens to read a null element, it should be ignored.

I just fixed a bug () with Set collections, where null elements were (incorrectly) being persisted.

Currently, there is an inconsistency with empty composite values. I am in the process of fixing that ().

This behavior does not depend on dialect. If Hibernate is adding a null element to a collection table, then that is a bug.

Gail Badner
July 22, 2017, 9:09 PM

If you are adding an empty string as a collection element, then Hibernate should persist the empty string in the collection table. If your database automatically converts empty strings to null, then you would end up with null in your collection table, and Hibernate would end up ignoring the collection element when it is read.

Gail Badner
July 25, 2017, 7:41 PM
Gail Badner
August 16, 2017, 9:57 PM

Rejecting because this is expected behavior.

Assignee

Andrea Boriero

Reporter

Petar Tahchiev

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Priority

Blocker
Configure