官术网_书友最值得收藏!

Step 3: Creating an entity class

An entity class is the main player in a JPA application. It's a class that represents a table in the database, whose instances, in turn, represent rows inside this table. An entity class is no more than a POJO, annotated with @Entity, with a field elected as a primary key and annotated with @Id, as in the following example:

Movie.java 
@Entity 
public class Movie { 
 
    @Id 
    @GeneratedValue 
    private long id; 
    private String title; 
 
    public Movie() { 
    } 
 
    public long getId() { 
        return id; 
    } 
 
    public void setId(long id) { 
        this.id = id; 
    } 
 
    public String getTitle() { 
        return title; 
    } 
 
    public void setTitle(String title) { 
        this.title = title; 
    } 
 
} 

Note that you do not have to create a corresponding table in the database yourself, as the persistence unit is declared with the javax.persistence.schema-generation.database.action property set to create, which means that the persistence provider is responsible for creating the table in the database, if it does not exist.

主站蜘蛛池模板: 隆尧县| 丰县| 青龙| 金坛市| 凭祥市| 连南| 贵南县| 互助| 民勤县| 竹山县| 庄河市| 黔东| 广德县| 乌恰县| 商城县| 通化市| 北碚区| 安丘市| 贡嘎县| 山东省| 普陀区| 江华| 马关县| 内丘县| 平山县| 吉林省| 兴城市| 洪泽县| 大姚县| 吉林市| 辛集市| 鄂托克旗| 永泰县| 宜宾县| 靖宇县| 芦山县| 太仆寺旗| 库尔勒市| 中阳县| 江陵县| 疏勒县|