Map in entities using @GenericGenerator(name="system-uuid", strategy =
"uuid") doesn't work
-------------------------------------------------------------------------------------------
Key: HHH-3043
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3043
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.5
Reporter: Pascal P. Pochet
Priority: Blocker
Attachments: Archive.zip
When using this entity declaration
@Id
@GeneratedValue
protected long id ;
@Type(type="language")
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
@MapKey(columns=@Column(name="language", length=6))
protected java.util.Map<Language,Label> itsLabels = new
HashMap<Language,Label>() ;
reading back of persisted Label associated with the entity works ok
When changing to
@Id
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(name="id", length=36)
protected String itsUUID = UUID.randomUUID().toString() ;
@Type(type="language")
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
@MapKey(columns=@Column(name="language", length=6))
protected java.util.Map<Language,Label> itsLabels = new
HashMap<Language,Label>() ;
persisted Label can't be retrieved anymore (the itsLabels Map is always empty) and
persisting new version of existing labels generates duplicate errors (of course...).
Tracking down the problem shows that different code is executed when the LAZY loading the
map is performed, the UUID-based version generating the reading of 4 times the same
Collection (there were 3 Label persisted for the test entity) and as consequence the
setter is not called leaving the Label Map empty (as initialized at constructor time)
Part of the debug trace :
[java] 17:43:03,090 DEBUG CollectionLoadContext:217 - 4 collections were found in result
set for role: eu.cec.sanco.sanref.valuelist.Individual.itsLabels
[java] 17:43:03,091 DEBUG CollectionLoadContext:260 - collection fully initialized:
[eu.cec.sanco.sanref.valuelist.Individual.itsLabels#ac7117a2-3c0c-4d40-90ba-3bef5a5c77eb]
[java] 17:43:03,091 DEBUG CollectionLoadContext:260 - collection fully initialized:
[eu.cec.sanco.sanref.valuelist.Individual.itsLabels#ac7117a2-3c0c-4d40-90ba-3bef5a5c77eb]
[java] 17:43:03,092 DEBUG CollectionLoadContext:260 - collection fully initialized:
[eu.cec.sanco.sanref.valuelist.Individual.itsLabels#ac7117a2-3c0c-4d40-90ba-3bef5a5c77eb]
[java] 17:43:03,092 DEBUG CollectionLoadContext:260 - collection fully initialized:
[eu.cec.sanco.sanref.valuelist.Individual.itsLabels#ac7117a2-3c0c-4d40-90ba-3bef5a5c77eb]
[java] 17:43:03,093 DEBUG CollectionLoadContext:226 - 4 collections initialized for role:
eu.cec.sanco.sanref.valuelist.Individual.itsLabels
[java] 17:43:03,093 DEBUG StatefulPersistenceContext:790 - initializing non-lazy
collections
[java] 17:43:03,094 DEBUG Loader:2010 - done loading collection
while on the Long id-based entity we got :
[java] 18:09:27,800 DEBUG CollectionLoadContext:217 - 1 collections were found in result
set for role: eu.cec.sanco.sanref.valuelist.Individual.itsLabels
[java] 18:09:27,801 DEBUG CollectionLoadContext:260 - collection fully initialized:
[eu.cec.sanco.sanref.valuelist.Individual.itsLabels#299]
[java] 18:09:27,801 DEBUG CollectionLoadContext:226 - 1 collections initialized for role:
eu.cec.sanco.sanref.valuelist.Individual.itsLabels
[java] 18:09:27,802 DEBUG StatefulPersistenceContext:790 - initializing non-lazy
collections
[java] 18:09:27,802 DEBUG Loader:2010 - done loading collection
Also in the trace of the UUID-based version, we see that Hibernate recursively load the
mapped entity (Label)
[java] 17:43:02,906 DEBUG Loader:1852 - loading entity:
[eu.cec.sanco.sanref.Label#0199f151-44f7-4704-9f09-72a42527590c]
(one "loading entity" message per persisted Label...)
while this is not happening when running the "GeneratedValue" version.
NB
The problem is not related to the usage of the UserType Language, testing as been done by
going back to a more basic <String,Label> map: the problem remains identical.
By stepping in the code, possible source of the problem may be related to the
"hasRowId" returned value in the UUID-based version. (not 100% sure...)
The 2 log files attached in 1 zip show the differences when lazy loading the Label map.
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira