[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (HHH-5024) MetadataContext#registerAttribute does not recognize inherited fields
Hardy Ferentschik (JIRA)
noreply at atlassian.com
Fri Jan 20 09:05:09 EST 2012
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5024?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45198#comment-45198 ]
Hardy Ferentschik edited comment on HHH-5024 at 1/20/12 8:03 AM:
-----------------------------------------------------------------
Ok, in _org.hibernate.ejb.test.metagen.mappedsuperclass.idclass_ we have:
{code:title=AbstractAttribute.java|borderStyle=solid}
@MappedSuperclass
public abstract class AbstractAttribute implements Serializable {
protected String key;
protected String value;
public AbstractAttribute() {
super();
}
public abstract String getOwner();
@Column(name = "attribute_key")
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}
{code:title=AbstractAttribute_.java|borderStyle=solid}
@StaticMetamodel(AbstractAttribute.class)
public abstract class AbstractAttribute_ {
public static volatile SingularAttribute<AbstractAttribute, String> value;
public static volatile SingularAttribute<AbstractAttribute, String> owner;
public static volatile SingularAttribute<AbstractAttribute, String> key;
}
{code}
----
{code:title=ProductAttribute.java|borderStyle=solid}
@Entity
@IdClass(value = ProductAttributeId.class)
public class ProductAttribute extends AbstractAttribute implements Serializable {
private String owner;
public ProductAttribute(String key, String value, String product) {
this.key = key;
this.value = value;
this.owner = product;
}
public ProductAttribute() {
super();
}
@Id
@Column(name = "owner")
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
@Id
@Column(name = "attribute_key")
public String getKey() {
return key;
}
}
{code}
{code:title=ProductAttribute_.java|borderStyle=solid}
@StaticMetamodel(ProductAttribute.class)
public abstract class ProductAttribute_ extends org.hibernate.ejb.test.metagen.mappedsuperclass.idclass.AbstractAttribute_ {
public static volatile SingularAttribute<ProductAttribute, String> owner;
public static volatile SingularAttribute<ProductAttribute, String> key;
}
{code}
----
{code:title=AbstractAttributeId.java|borderStyle=solid}
@MappedSuperclass
public abstract class AbstractAttributeId implements Serializable {
protected String key;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
{code}
{code:title=AbstractAttributeId_.java|borderStyle=solid}
@StaticMetamodel(AbstractAttributeId.class)
public abstract class AbstractAttributeId_ {
public static volatile SingularAttribute<AbstractAttributeId, String> key;
}
{code}
----
{code:title=ProductAttributeId.java|borderStyle=solid}
public class ProductAttributeId extends AbstractAttributeId {
private String owner;
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
@Override
public int hashCode() {
...
}
@Override
public boolean equals(Object obj) {
...
}
}
{code}
----
What do you think is wrong in the metamodel classes?
was (Author: hardy.ferentschik):
Ok, in _org.hibernate.ejb.test.metagen.mappedsuperclass.idclass_ we have:
{code:title=AbstractAttribute.java|borderStyle=solid}}
@MappedSuperclass
public abstract class AbstractAttribute implements Serializable {
protected String key;
protected String value;
public AbstractAttribute() {
super();
}
public abstract String getOwner();
@Column(name = "attribute_key")
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}
{code:title=AbstractAttribute_.java|borderStyle=solid}}
@StaticMetamodel(AbstractAttribute.class)
public abstract class AbstractAttribute_ {
public static volatile SingularAttribute<AbstractAttribute, String> value;
public static volatile SingularAttribute<AbstractAttribute, String> owner;
public static volatile SingularAttribute<AbstractAttribute, String> key;
}
{code}
----
{code:title=ProductAttribute.java|borderStyle=solid}}
@Entity
@IdClass(value = ProductAttributeId.class)
public class ProductAttribute extends AbstractAttribute implements Serializable {
private String owner;
public ProductAttribute(String key, String value, String product) {
this.key = key;
this.value = value;
this.owner = product;
}
public ProductAttribute() {
super();
}
@Id
@Column(name = "owner")
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
@Id
@Column(name = "attribute_key")
public String getKey() {
return key;
}
}
{code}
{code:title=ProductAttribute_.java|borderStyle=solid}}
@StaticMetamodel(ProductAttribute.class)
public abstract class ProductAttribute_ extends org.hibernate.ejb.test.metagen.mappedsuperclass.idclass.AbstractAttribute_ {
public static volatile SingularAttribute<ProductAttribute, String> owner;
public static volatile SingularAttribute<ProductAttribute, String> key;
}
{code}
----
{code:title=AbstractAttributeId.java|borderStyle=solid}}
@MappedSuperclass
public abstract class AbstractAttributeId implements Serializable {
protected String key;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
{code}
{code:title=AbstractAttributeId_.java|borderStyle=solid}}
@StaticMetamodel(AbstractAttributeId.class)
public abstract class AbstractAttributeId_ {
public static volatile SingularAttribute<AbstractAttributeId, String> key;
}
{code}
----
{code:title=ProductAttributeId.java|borderStyle=solid}}
public class ProductAttributeId extends AbstractAttributeId {
private String owner;
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
@Override
public int hashCode() {
...
}
@Override
public boolean equals(Object obj) {
...
}
}
{code}
----
What do you think is wrong in the metamodel classes?
> 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
More information about the hibernate-issues
mailing list