开发者

Can annotation be added to decelerations

开发者 https://www.devze.com 2023-01-07 02:03 出处:网络
Can we add annotations to the decelerations instead to the getter methods. I\'m used to this @Column(name=\"Part_ID\")

Can we add annotations to the decelerations instead to the getter methods.

I'm used to this

 @Column(name="Part_ID")
   public Long getPartId() {
   return partId;
 }

Can we us开发者_JAVA技巧e it like this

@Column(name="Part_ID")
private Long partId;

Thanks all.

Ravi


Yes, you can. See section 2.2.2.2 of the Hibernate annotations documentation:

By default the access type of a class hierarchy is defined by the position of the @Id or @EmbeddedId annotations. If these annotations are on a field, then only fields are considered for persistence and the state is accessed via the field. If there annotations are on a getter, then only the getters are considered for persistence and the state is accessed via the getter/setter. That works well in practice and is the recommended approach.

So if you put your @Id on a field, then Hibernate will look at annotations on the fields for the other properties. If you put @Id on a getter, then Hibernate will look at annotations on the other getters.

0

精彩评论

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