2 Replies Latest reply on Feb 9, 2006 3:36 PM by epbernard

    Mixing annotations at field/setters

    doegi

      Hi!

      I don't know wether this is a bug or required by the spec. However, I couldn't figure how to file it into JIRA as an unregistered user, and JIRA wouldn't let me register as a new user, so I have to post it here.

      If you make differences in how you annotate the fields in
      I have this simple class:

      @Embeddable
      public class BlaPK
       implements Serializable {
      
       private Long id;
      
       private Integer type = TYPE_UNSPECIFIED;
      
       @Column(name="bla_pk_id")
       public Long getId() {
       return id;
       }
      
       public void setId(Long id) {
       this.id = id;
       }
      
      
       @Column(name="bla_pk_type")
       public Integer getType() {
       return type;
       }
       public void setType(Integer type) {
       this.type = type;
       }
      }
      
      
      @Entity
      public class Foo implements Serializable {
       @Id
       private Long id;
      
       @Embedded
       private BlaPK bla;
      
       // getters and setts for id/bla
      }
      


      JBoss will throw a "duplicate column id" error for class Foo. It doesn't seem to see the @Column name override in the @Embeddable class which are set on the getters.

      This used to work in JBoss 4.0.3SP1. However, in 4.0.4RC1 I have to move the annotations in the BlaPK class to the fields as well. I have the impression JBoss makes a lookup for class Foo and sees field-wise annotations, and hence doesn't recognize the annocations at the functions when it inspects the @Embedded class.

      I don't know if this required by the spec, if not, take this as a bug report (and again, sorry for not filing in JIRA).




        • 1. Re: Mixing annotations at field/setters
          patrick_ibg

          The new spec by default does not allow mixed field and method access on an entity, it's mapped superclass and embedded entities. There is a way around this, if you really want to do it (check the spec).

          Before, the @Entity annotation took an AccessType.FIELD or AccessType.METHOD attribute. This is no longer the case. The access type is now determined by whether you annotate the entity's @Id on the field or method. This is inherited by @Embeddable and when extending @MappedSuperclass.

          • 2. Re: Mixing annotations at field/setters
            epbernard

            Note that you can fall back to the previous behavior using @o.h.a.AccessType