views:

32

answers:

1

Hello All,

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 use it like this

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

Thanks all.

Ravi

+1  A: 

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.

skaffman