@MapKey throws an exception if the key is part of a non-embedded composite ID
-----------------------------------------------------------------------------
Key: ANN-599
URL:
http://opensource.atlassian.com/projects/hibernate/browse/ANN-599
Project: Hibernate Annotations
Issue Type: Bug
Components: binder
Affects Versions: 3.3.0.ga
Environment: Hibernate Core 3.2.3, Annotations 3.3.0.GA, Oracle 9i, Java5
Reporter: Chris Rose
Priority: Minor
Like mentioned in ANN-43, the property binder for MapKey does not completely handle
identifier properties in the owned entity. Unlike that issue, which is clearly fixed,
this issue comes when the mapped entity has a composite primary key that is _not_ handled
with a separate PK class.
For example:
class Owner {
@Id
Long getOwnerId () {}
@OneToMany(mappedBy="owner")
@MapKey(name="propertyName")
Map<String,Value> getProperties (){}
}
class Value {
@Id
String getPropertyName () {}
@Id
Long getOwnerId (){}
@ManyToOne
@JoinColumn(name="owner_id")
Owner getOwner ()
}
This generates an exception when I initialize the session:
11:36:27,800 INFO CollectionBinder:627 - Mapping collection: Owner.properties ->
properties
Exception in thread "main" org.hibernate.AnnotationException: Map key property
not found: Value.propertyName
at
org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable(MapBinder.java:103)
at org.hibernate.cfg.annotations.MapBinder.access$000(MapBinder.java:53)
at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:83)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at
org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at com.planet.core.SessionFactoryTest.main(SessionFactoryTest.java:46)
From the code, it's clear that the BinderHelper.findPropertyByName
() method only acquires the _first_ identifier property on the Value class, which appears
to be the alphabetically first one, rather than the multiple ones.
--
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