[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5024) MetadataContext#registerAttribute does not recognize inherited fields

Justin Wesley (JIRA) noreply at atlassian.com
Mon Jan 9 10:08:10 EST 2012


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5024?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45030#comment-45030 ] 

Justin Wesley commented on HHH-5024:
------------------------------------

The problem looks to be when you have an entity that extends a MappedSuperclass, and the MappedSuperclass has an EmbeddedId/Id property. The metamodel property for the EmbeddedId/Id property does not get populated. The following classes will fail the test when checking for Product_.id.

{code:title=Product.java|borderStyle=solid}
@Entity
public class Product extends AbstractProduct {

	private String description;
	
	public Product() {
	}
	
	@Column
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
}
{code}
{code:title=AbstractProduct.java|borderStyle=solid}
@MappedSuperclass
public class AbstractProduct implements Serializable {
	private ProductId id;
	
	public AbstractProduct() {
	}

	@EmbeddedId
	public ProductId getId() {
		return id;
	}

	public void setId(ProductId id) {
		this.id = id;
	}
}
{code}
{code:title=ProductId.java|borderStyle=solid}
@Embeddable
public class ProductId implements Serializable {
	private Integer id;
	private String code;

	public ProductId() {
	}

	@Column
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

}
{code}

> MetadataContext#registerAttribute does not recognize inherited fields
> ---------------------------------------------------------------------
>
>                 Key: HHH-5024
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5024
>             Project: Hibernate Core
>          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
>         Attachments: bugreport.zip, hhh-5024.zip
>
>          Time Spent: 3.5h
>
> 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