Hibernate/JPA - annotating bean methods vs fields

Posted by Benju on Stack Overflow See other posts from Stack Overflow or by Benju
Published on 2009-06-02T21:37:10Z Indexed on 2010/05/10 11:54 UTC
Read the original article Hit count: 256

Filed under:
|
|
|

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;
}

}

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about jpa