javax. Persistence field, comment of getter or setter?
•
Java
I am learning hibernate and Java persistence API
I have a @ entity class that needs to annotate each field I've listed three places they can go in the code below
Should I apply them to the site itself, a getter or an aspirator? What are the semantic differences (if any) between the three options
import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Id; @Entity @Table(name = "song") public class Song { // Annotations should only be applied to one of the below @Id @Column(name="id",unique=true,nullable=false) private int id; @Id @Column(name="id",nullable=false) public int getId() { return id; } @Id @Column(name="id",nullable=false) public void setId(int id) { this.id = id; } }
Solution
You have to choose between the site and the getter Comments on setters are not supported All comments should be on fields, or they should be on getters: you can't mix the two methods (unless you use the @ accesstype comment)
The answer to which one I prefer is: it depends on I prefer site visits, but YMMV, and in some cases, property visits are my favorite See @ L_ 404_ 2@.
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码