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

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.

主站蜘蛛池模板: 桦南县| 莱州市| 龙州县| 陈巴尔虎旗| 蒙自县| 湘潭市| 武宣县| 河南省| 临安市| 玛曲县| 尼木县| 肇庆市| 霸州市| 三江| 莎车县| 鲁山县| 巴马| 岳普湖县| 万州区| 建德市| 灵川县| 巴南区| 湘乡市| 肇庆市| 榕江县| 融水| 和林格尔县| 石嘴山市| 平潭县| 松滋市| 新巴尔虎右旗| 色达县| 苏尼特右旗| 东乌珠穆沁旗| 张家口市| 布拖县| 南涧| 商水县| 中卫市| 柳州市| 长汀县|