- Developing Middleware in Java EE 8
- Abdalla Mahmoud
- 199字
- 2021-07-23 19:24:37
Column mapping
By default, all fields (or getter methods, according to @Id place) are mapped as columns in the containing table, with a default name matching the field (or getter) name, and a default type matching its Java type, if you need to customize how a column is mapped in the database, as in the following code snippet:
@Entity public class Movie { @Column(name = "movie_title") private String title; .... }
In the previous example, we have customized the name of the title field to movie_title. Moreover, the previous example maps by default to the database type VARCHAR. As you know, VARCHAR types have a length. The default length of a VARCHAR field in JPA is 255, but you can customize this value by using the length attribute:
@Entity public class Movie { @Column(name = "movie_title", length=100) private String title; .... }
If you have a text type available in your database, you can also modify the default type by using the columnDefinition attribute:
@Entity public class Movie { @Column(name = "movie_title", columnDefinition = "text") private String title; .... }
Other attributes are available for the customization of table columns, as shown in the following table:

- C及C++程序設計(第4版)
- Flask Web開發入門、進階與實戰
- PHP網絡編程學習筆記
- PostgreSQL 11從入門到精通(視頻教學版)
- C語言程序設計案例精粹
- Mastering Ext JS
- jQuery Mobile移動應用開發實戰(第3版)
- PHP+MySQL+Dreamweaver動態網站開發從入門到精通(第3版)
- 蘋果的產品設計之道:創建優秀產品、服務和用戶體驗的七個原則
- JavaScript應用開發實踐指南
- 深入實踐DDD:以DSL驅動復雜軟件開發
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動化處理
- Wearable:Tech Projects with the Raspberry Pi Zero
- 零基礎學編程系列(全5冊)
- Getting Started with Web Components