- Developing Middleware in Java EE 8
- Abdalla Mahmoud
- 166字
- 2021-07-23 19:24:36
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.
推薦閱讀
- FuelPHP Application Development Blueprints
- SoapUI Cookbook
- OpenCV實例精解
- Java編程指南:基礎知識、類庫應用及案例設計
- Python編程完全入門教程
- Data Analysis with Stata
- Visual Basic程序設計實踐教程
- 智能手機故障檢測與維修從入門到精通
- SQL Server 入門很輕松(微課超值版)
- Java 從入門到項目實踐(超值版)
- Emotional Intelligence for IT Professionals
- PHP 8從入門到精通(視頻教學版)
- Selenium WebDriver Practical Guide
- 安卓工程師教你玩轉Android
- Qt 5.12實戰