[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3836) composite-element with null columns in map is ignored

Karl von Randow (JIRA) noreply at atlassian.com
Thu Nov 25 18:15:13 EST 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3836?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39216#action_39216 ] 

Karl von Randow commented on HHH-3836:
--------------------------------------

Thanks Olivier, your workaround just saved me a lot of time!

I have traced the problem to ComponentType.hydrate(...) on line 602 (in 3.6 source):
return notNull ? values : null;

Where notNull is set to true if any of the properties in the component aren't null (hence your fix works).

It seems that it's desirable behaviour to have an empty component class returned rather than just a null in the Map scenario (which is what we were all expecting), but this is the expected behaviour (Hibernate reference 8.1 para 5). The workaround works so maybe that's what should be done... perhaps something about this could be added to the docs. You could potentially just add a dummy property formula="1" to workaround without having more columns?

My $0.02

> 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