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

- 程序員修煉之道:程序設計入門30講
- 大學計算機應用基礎實踐教程
- Microsoft Application Virtualization Cookbook
- 兩周自制腳本語言
- 算法基礎:打開程序設計之門
- PyTorch自然語言處理入門與實戰(zhàn)
- VMware vSphere 6.7虛擬化架構實戰(zhàn)指南
- RabbitMQ Essentials
- Android Wear Projects
- INSTANT Adobe Edge Inspect Starter
- 機器學習微積分一本通(Python版)
- 移動增值應用開發(fā)技術導論
- SpringBoot從零開始學(視頻教學版)
- Practical Predictive Analytics
- JBoss AS 7 Development