- 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.
推薦閱讀
- UNIX編程藝術(shù)
- Visual Basic .NET程序設(shè)計(jì)(第3版)
- 軟件架構(gòu)設(shè)計(jì):大型網(wǎng)站技術(shù)架構(gòu)與業(yè)務(wù)架構(gòu)融合之道
- Web Scraping with Python
- 無代碼編程:用云表搭建企業(yè)數(shù)字化管理平臺
- 青少年美育趣味課堂:XMind思維導(dǎo)圖制作
- Responsive Web Design with HTML5 and CSS3
- Functional Programming in JavaScript
- Java 11 Cookbook
- Unreal Engine 4 Shaders and Effects Cookbook
- WebRTC技術(shù)詳解:從0到1構(gòu)建多人視頻會議系統(tǒng)
- Android移動開發(fā)案例教程:基于Android Studio開發(fā)環(huán)境
- JavaScript腳本特效編程給力起飛
- UI設(shè)計(jì)基礎(chǔ)培訓(xùn)教程(全彩版)
- 深入理解Java虛擬機(jī):JVM高級特性與最佳實(shí)踐