[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5393?page=c...
]
Harald Wellmann commented on HHH-5393:
--------------------------------------
Actually, this is not quite the same thing as HHH-5136 (or maybe I shouldn't have
mixed two aspects in that earlier issue).
HHH-5136 was mainly about the fact that overriding the mapped table and column names only
works when the mappings are specified by annotations and has no effect when using XML
mappings instead.
Meanwhile, I've had some interesting feedback on this from Mike Keith (see the
comments to my blog post cited above). As Mike points out, @MapKey was only intended by
the spec for the case Map<Basic, Entity>, not for Map<Basic, Embeddable>. The
correct annotation for embeddable values would be
@MapKeyColumn(name = "language", insertable = false, updatable = false)
But in this case, I get the following exception from Hibernate:
org.hibernate.MappingException: Repeated column in mapping for collection:
MultilingualString.map column: language
@MapKey with embeddable value
-----------------------------
Key: HHH-5393
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5393
Project: Hibernate Core
Issue Type: Bug
Components: annotations
Affects Versions: 3.5.3
Environment: Hibernate 3.5.3, PostgreSQL 8.4.3
Reporter: Harald Wellmann
Assignee: Gail Badner
Map<Basic, Embeddable> does not work, when the map key is a persistent field of the
value. The map key shall not be represented as a separate table column, this is why the
example uses @MapKey and not @MapKeyColumn.
Example:
{code:java}
@Embeddable
public class LocalizedString {
private String language;
private String text;
}
@Entity
public class MultilingualString {
@Id
private long id;
@ElementCollection(fetch=FetchType.EAGER)
@MapKey(name = "language")
@CollectionTable(schema = "jpa", name =
"multilingual_string_map",
joinColumns = @JoinColumn(name = "string_id"))
private Map<String, LocalizedString> map = new HashMap<String,
LocalizedString>();
}
{code}
Hibernate appears to expect an Entity as map value:
org.hibernate.AnnotationException: Associated class not found: LocalizedString
Detailed discussion of this use case:
http://hwellmann.blogspot.com/2010/07/jpa-20-mapping-map.html
--
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