[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6581) JPA 2.0 Spec. Violation with Access and MappedSuperclass

Laird Nelson (JIRA) noreply at atlassian.com
Wed Aug 17 11:57:08 EDT 2011


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

Laird Nelson commented on HHH-6581:
-----------------------------------

Confirmed that the problem also exists in 4.0.0.Beta4.

> JPA 2.0 Spec. Violation with Access and MappedSuperclass
> --------------------------------------------------------
>
>                 Key: HHH-6581
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6581
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: annotations, core
>    Affects Versions: 3.6.6
>            Reporter: Laird Nelson
>              Labels: jpa2
>         Attachments: hhh-6581.zip
>
>
> Once I create this issue and get the bug number I will be creating a test case.
> The bug is fully described in the Hibernate user forums: https://forum.hibernate.org/viewtopic.php?f=1&t=1012254
> Suppose I have a {{@MappedSuperclass}} like this:
> {code:title=A.java}
> @Access(AccessType.FIELD)
> @MappedSuperclass
> public class A {
>   private long id;
>   @Column(name = "some_other_field")
>   private String someOtherField;
>   @Access(AccessType.PROPERTY)
>   @Column(name = "id")
>   @GeneratedValue
>   @Id
>   public long getId() {
>     return this.id;
>   }
>   protected void setId(final long id) {
>     this.id = id;
>   }
> }
> {code}
> Then suppose I extend it with a (minimally-annotated) entity:
> {code:title=B.java}
> @Entity
> @Table(name = "b")
> public class B extends A {
>   @Column(name = "long_description")
>   private String longDescription;
>   // various other persistent fields here
>   public String getLongDescription() {
>     return this.longDescription;
>   }
>   public void setLongDescription(final String description) {
>     this.longDescription = description;
>   }
> }
> {code}
> Hibernate 3.6.6.Final logs exceptions indicating that it cannot find the {{LONGDESCRIPTION}} column for this entity.  This implies that somehow {{AccessType.PROPERTY}} has been used on the longDescription attribute, where {{AccessType.FIELD}} should have been used instead.  This is a violation of the spec.
> It's almost like the mere fact that {{AccessType.PROPERTY}} was used in the {{@MappedSuperclass}} at all caused it to be "latched" as the default for the rest of the entity hierarchy, which is clearly not what should happen.
> Section 2.3.2 in the JPA 2.0 specification reads as follows:
> bq. An access type for an individual entity class, mapped superclass, or embeddable class can be specified for that class independent of the default for the entity hierarchy by means of the Access annotation applied to the class. This explicit access type specification does not affect the access type of other entity classes or mapped superclasses in the entity hierarchy.
> Then it also says, later:
> bq. Persistent state inherited from superclasses is accessed in accordance with the access types of those superclasses.
> My interpretation of all this is that I shouldn't have to put the {{@Access}} annotation on the {{@Entity}} in my example above.  {{B.java}} should inherit the fact that the "{{id}}" property has {{AccessType.PROPERTY}}, and, by virtue of the default algorithm specified in section 3.2.1, should apply {{AccessType.FIELD}} to all other elements of its persistent state.
> Guy Pelletier from EclipseLink, upon having this all explained to him, says:
> bq. The behavior you describe is indeed intentionally implemented that way [i.e. no extra @Access annotation on B.java required] in EclipseLink as this is also our interpretation of the spec as well (and we confirmed with direct discussions with members of the spec committee beforehand).
> I'll put a test case together shortly.

--
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