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

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.

主站蜘蛛池模板: 邛崃市| 湖口县| 遂宁市| 宁化县| 海南省| 惠水县| 锡林郭勒盟| 奉新县| 积石山| 巴塘县| 蓬溪县| 玉门市| 太湖县| 阜宁县| 宝清县| 会宁县| 青田县| 潜山县| 建阳市| 资源县| 汉源县| 青铜峡市| 繁昌县| 涟水县| 安图县| 盘锦市| 启东市| 泾源县| 湘乡市| 漳平市| 隆尧县| 买车| 尼玛县| 正安县| 孟津县| 金华市| 久治县| 云阳县| 青阳县| 于田县| 崇义县|