這是註釋字段和註釋方法(通常爲getter)之間的區別?JPA 2.0中的JPA 2.0字段註釋與方法註釋
與現場註解實施例
@Entity
public class MainEntity {
@Id
private Long id
@OneToMany
private RelatedEntity relatedEntity
//getters and setters and possible other methods
...
}
與方法註解
@Entity
public class MainEntity {
@Id
private Long id;
private RelatedEntity relatedEntity
//getters and setters and possible other methods
@OneToMany
public RelatedEntity getRelatedEntity(){
return relatedEntity
}
//other methods etc
...
}
的區別是什麼?在一個你註釋的領域和其他方法!對於持久性來說,自JPA提供者同時支持這兩種方式沒有區別。除此之外,它完全是基於意見的 –