[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3836) composite-element with null columns in map is ignored
Olivier Lafontaine (JIRA)
noreply at atlassian.com
Thu Oct 7 12:03:57 EDT 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3836?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38618#action_38618 ]
Olivier Lafontaine commented on HHH-3836:
-----------------------------------------
I do have the same problem, but found a workaround.
This is quite ugly, but you can map the map-key property inside the composite-element. This requires modifying the component to include the attribute. Note that you need to use the formula attribute instead of the column attribute else you're gonna end up with the "duplicate column in mapping" problem.
Here's an example:
{noformat}
<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="mapId" formula="map_id" />
<!-- other properties -->
</composite-element>
</map>
{noformat}
> composite-element with null columns in map is ignored
> -----------------------------------------------------
>
> Key: HHH-3836
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3836
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.3.0.SP1
> Environment: 3.3.0 SP1, noticed with Oracle and H2 but probably happens with all databases
> Reporter: Benoit Goudreault-Emond
> Attachments: HHH-3836.zip, patate.zip
>
>
> 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.
--
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