- 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:

- Scratch真好玩:教小孩學編程
- Learning Python by Building Games
- Unity 3D腳本編程:使用C#語言開發跨平臺游戲
- MINECRAFT編程:使用Python語言玩轉我的世界
- Deep Learning with R Cookbook
- Mudbox 2013 Cookbook
- Python Web自動化測試設計與實現
- Python全棧開發:基礎入門
- Splunk Essentials
- SOA Patterns with BizTalk Server 2013 and Microsoft Azure(Second Edition)
- Django 2.0 入門與實踐
- Isomorphic JavaScript Web Development
- HTML5+CSS3+JavaScript案例實戰
- Go語言Hyperledger區塊鏈開發實戰
- 新手學Visual C