[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5024?page=c...
]
Steve Ebersole commented on HHH-5024:
-------------------------------------
So the tests I created from these issues show what we think are 2 different
"issues".
First, the specific case Hardy and I were discussing above which came originally from
Alexis. We both agree this is just incorrect mapping. Specifically, attributes defined
on a {{MappedSuperclass}} can be "overridden" on an entity sub class, but the
proper way to do that is to use ((AttributeOverrides)). And there is no spec provided way
to say that a basic attribute defined on a {{MappedSuperclass}} become {{Id}} mappings on
an entity sub class. Given that model, we think the correct way to map that to match the
intent and meet the spec is to mark those 2 attributes as {{Transient}} on the
{{MappedSuperclass}} like so:
{code:title=AbstractAttribute.java|borderStyle=solid}
@MappedSuperclass
public abstract class AbstractAttribute implements Serializable {
protected String key;
protected String value;
public AbstractAttribute() {
super();
}
@Transient
public abstract String getOwner();
@Transient
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Column(name = "attribute_value")
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
{code}
The entity class stays as it was. And this works in terms of both the metamodel generator
and Hibernate populating that static metamodel.
----
The second issue deals with "embeddable" classes defined on a
{{MappedSuperclass}}. This holds true for both {{Embedded}} and {{EmbeddedId}}. The
issue is the way in which support for {{MappedSuperclass}} was originally "bolted
on" to the existing Hibernate {{PersistentClass}} mapping classes. Changing the
{{getDeclaredField}} call to {{getField}} as suggested here is really just a band aid.
But we will make that change for embeddable attributes for 4.1 as better solutions are
already targeted for 5.0
MetadataContext#registerAttribute does not recognize inherited
fields
---------------------------------------------------------------------
Key: HHH-5024
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5024
Project: Hibernate ORM
Issue Type: Bug
Components: entity-manager, metamodel
Affects Versions: 3.5.0-CR-2, 3.5.1, 4.0.0.Final
Environment: Hibernate 3.5.0-CR-2, JPA Modelgen 1.0.0-CR-1
Reporter: Adrian Hummel
Assignee: Steve Ebersole
Fix For: 4.1.0
Attachments: bugreport.zip, hhh-5024.zip, hhh-5024.zip
Time Spent: 6.85h
The embeddable class {{CustomerId}} (see attached ZIP) inherits from the base class
{{AbstractIdentity}} (annotated with {{@MappedSuperclass}}). The metamodel classes for
these two classes are correctly generated:
{code:title=AbstractIdentity_.java|borderStyle=solid}
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@StaticMetamodel(AbstractIdentity.class)
public abstract class AbstractIdentity_ {
public static volatile SingularAttribute<AbstractIdentity, String> id;
}
{code}
and
{code:title=CustomerId_.java|borderStyle=solid}
import javax.persistence.metamodel.StaticMetamodel;
@StaticMetamodel(CustomerId.class)
public abstract class CustomerId_ extends AbstractIdentity_ {
}
{code}
When building the entity manager factory, {{MetadataContext#registerAttribute}} (line
378) tries to resolve the field {{CustomerId_.id}} using {{Class#getDeclaredField}}. This
results in a {{NoSuchFieldException}} because the field is declared in the super class
{{AbstractIdentity_}}.
Proposed solution: Since all field declarations in the metamodel are public, the
{{Class#getField}} method should be used instead.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira