Hibernate / JPA - 注释bean方法vs字段 [英] Hibernate/JPA - annotating bean methods vs fields
问题描述
我有一个关于Hibernate使用的简单问题。我一直以两种方式之一看到使用JPA注释的人注释类的字段,并注释相应bean的get方法。
我的问题是如下所示:注释字段和bean方法与JPA批注(如@Id)之间是否存在差异。
$ b 示例:
@Entity
public class User
{
** @ ID **
private int id;
public int getId(){
return this.id;
}
public void setId(int id){
this.id = id;
}
}
------- ---- OR -----------
@Entity
public class User
{
private int id;
** @ ID **
public int getId(){
return this.id;
}
public void setId(int id){
this.id = id;
}
}
是的,我相信你想在字段和属性访问上进行搜索:
Hibernate Annotations - 哪个更好,字段或属性访问?
Spring首选项是字段访问权限。这就是我所追求的。
I have a simple question about usage of Hibernate. I keep seeing people using JPA annotations in one of two ways by annotating the fields of a class and also by annotating the get method on the corresponding beans.
My question is as follows: Is there a difference between annotating fields and bean methods with JPA annoations such as @Id.
example:
@Entity
public class User
{
**@ID**
private int id;
public int getId(){
return this.id;
}
public void setId(int id){
this.id=id;
}
}
-----------OR-----------
@Entity
public class User
{
private int id;
**@ID**
public int getId(){
return this.id;
}
public void setId(int id){
this.id=id;
}
}
Yes, I believe you want to search on field versus property access:
Hibernate Annotations - Which is better, field or property access?
The Spring preference is field access. That's what I follow.
这篇关于Hibernate / JPA - 注释bean方法vs字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!