开发者

Hibernate not JPA compliant regarding @Access?

According to my JPA 2.0 book (and online documentation), I should be able to mix field and property access within a single entity or entity hierarchy. The annotation of @Access on the class specifies the default access. When placed on a field or property getter @Access can specify that the default should be overridden for this field.

@Entity
@Access(AccessType.FIELD)
Class Foo {

  @Id
  int id;

  @Column(name = "myfield")
  String myField;

  @Column(name = "myProp")
  @Access(AccessType.PROPERTY)
  public int getMyProp () {
    return 3;
  }

  public void setMyProp (i开发者_如何学Gont p) {
    // do nothing
  }
}

This class should result in a table with three columns. However it doesn't with Hibernate...the "myProp" column is missing from the table because apparently Hibernate takes its field vs property cue from the entity ID and runs with it...totally ignoring the JPA spec with regards to @Access.

Can anyone confirm this or did I make a stupid mistake somewhere?


I've seen similar (not the same but similar) issues like HHH-5004 so I wouldn't exclude that this might be a new one (the TCK doesn't seem exhaustive). But what version of Hibernate are you using? Did you try with the latest?


Based on the docs your code seems to be right. The @Access(AccessType.FIELD) annotation on top is unnecessary, because you annotated the field int id; This tells hibernate to use field access. I tried a very similar example with annotations and xml config mixed. This leads to the same behaviour, so it's probably a bug in hibernate.

I tried with hibernate 3.5.3

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜