composite-element with null columns in map is ignored

Description

When a composite element with all properties set to NULL is inserted in a map of the said composite element, the data gets inserted to the database but is never retreived when reloading the entity.

For instance, with an entity

@Entity
public class TestEntity {
@Id
private int id;
@CollectionOfElements
private Map<String, AccessPeriod> roleAccesses = new HashMap<String, AccessPeriod>();
// boilerplate getters/setters/etc omitted
}

And AccessPeriod being
@Embeddable
public class AccessPeriod {
public Date startDate;
public Date endDate;
}

If you insert in the map an AccessPeriod with both startDate and endDate set to null and persist the TestEntity,
an entry is inserted in the auxiliary table, but when getting the TestEntity back, the map is empty.

You get the same problem with a mapping file.

This used to work in Hibernate 2.1--I found this out while porting some code to 3.3.

See the attached example. You'll need to include Hibernate and h2 (com.h2database:h2 1.0.20061217) on your classpath to run it with the given jdbc.properties, but feel free to change it.

Environment

3.3.0 SP1, noticed with Oracle and H2 but probably happens with all databases

Activity

Show:
looyo wang
September 16, 2011, 2:59 AM

to Olivier:

I have the Primary Key Class in the componet.
I don't known how to configure the component. I try to set name="pkinstance.mapId",but hibernate can not identify it.

<map name="someMap" table="MAP_TABLE" cascade="all-delete-orphan" fetch="join">
<key column="my_id" not-null="true" />
<map-key column="map_id">
<composite-element class="SomeComponent">
<property name="pkinstance.mapId" formula="map_id" />
<!-- other properties -->
</composite-element>
</map>

Olivier Lafontaine
September 16, 2011, 3:24 AM

Looks like you have a nested composite element. I suggest you read about the nested-composite-element mapping in the docs.

looyo wang
September 16, 2011, 3:09 PM

to Olivier:
"composite-element with null columns in map is ignored" is a bug of the hibernate?

Brett Meyer
April 7, 2014, 5:46 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!

Brett Meyer
July 8, 2014, 3:10 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!

Rejected

Assignee

Unassigned

Reporter

Benoit Goudreault-Emond

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure