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

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.

主站蜘蛛池模板: 澄迈县| 武川县| 耒阳市| 远安县| 巫溪县| 新龙县| 咸宁市| 镇巴县| 明溪县| 托克逊县| 天长市| 凤庆县| 师宗县| 察哈| 锦屏县| 临夏县| 海晏县| 成都市| 平阳县| 松江区| 孟村| 浦东新区| 长子县| 墨江| 合江县| 宁国市| 酉阳| 柳河县| 那坡县| 乐都县| 贵溪市| 富阳市| 含山县| 灌南县| 清丰县| 读书| 江阴市| 崇明县| 邯郸市| 昭通市| 托克逊县|