- EJB 3 Developer Guide
- Michael Sikora
- 344字
- 2021-07-02 11:34:55
Overriding Metadata Defaults
In this section we return to the Customer entity and override some of the default mapping options.
First we want to use the CLIENT
table with columns CUSTOMER_ID, FIRST_NAME
and LAST_NAME
to store Customer entities. The primary key is CUSTOMER_ID
. The table definition is:

The modified listing for Customer.java
is shown below:
@Entity
@Table(name = "CLIENT")
public class Customer implements java.io.Serializable {
private int id;
private String firstName;
private String lastName;
public Customer() {};
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "CUSTOMER_ID")
public int getId() { return id; }
public void setId(int id) { this.id = id; }
@Column(name = "FIRST_NAME")
public String getFirstname() { return firstName; }
public void setFirstname(String firstName) {
this.firstName = firstName;
}
@Column(name = "LAST_NAME")
public String getLastname() { return lastName; }
public void setLastname(String lastName) {
this.lastName = lastName;
}
public String toString() {
return "[Customer Id =" + id + ",first name=" +
firstName + ",last name=" + lastName + "]";
}
}
Note we have used the @Table
annotation to specify the table name as CLIENT
. The default table name is the entity name, CUSTOMER
in our example. The catalog
element specifies the database catalog where the table is located. Many database systems, Derby included, do not support the concept of a catalog. So in our example we can leave this element out. The schema
element specifies the database schema where the table is located. The default is persistence provider specific, in the case of the GlassFish APP
is the default schema for the embedded Derby database. Again, in our example, we rely on the default.
We have explicitly specified an AUTO
primary key generation strategy:
@Id @GeneratedValue(strategy=GenerationType.AUTO)
Recall that GlassFish selects the TABLE
strategy in this case.
Recall that by default column names are set to attribute names. To override this we use the @Column
annotation. For example,
@Column(name = "CUSTOMER_ID") public int getId() { return id; }
will map the id
attribute to the CUSTOMER_ID
column. In a similar fashion we map the firstName
and lastName
attributes to the FIRST_NAME
and LAST_NAME
columns respectively.
- 3ds Max & Unreal Engine 4:VR三維建模技術實例教程(附VR模型)
- COSPLAY的后期藝術:Lightroom+Photoshop修圖技法攻略
- 新編三維CAD習題集
- Instant Microsoft SQL Server Analysis Services 2012 Dimensions and Cube
- 數字創意大師:Alias二維與三維概念設計工作流淺析
- 輕松玩轉3D One AI
- 好學、好用、好玩的Photoshop 寫給初學者的入門書(第4版)
- AutoCAD 2016中文版基礎教程(全圖解視頻版)
- 中文版Flash CS6動畫制作(慕課版)
- IBM Lotus Notes and Domino 8.5.1
- Science Teaching with Moodle 2.0
- Photoshop+Firefly從入門到精通
- AI寫實人物繪畫關鍵詞圖鑒(Stable Diffusion版)
- AutoCAD 2019中文版完全自學手冊(標準版)
- 老郵差 Photoshop數碼照片處理技法 圖層篇(修訂版)