官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 宜都市| 咸丰县| 商洛市| 班玛县| 乃东县| 周宁县| 赞皇县| 浠水县| 兴城市| 平凉市| 山东| 盖州市| 宁城县| 定结县| 福泉市| 太白县| 潮州市| 珠海市| 成安县| 海淀区| 刚察县| 蓬莱市| 香港| 应用必备| 甘肃省| 健康| 兴文县| 大新县| 平遥县| 福安市| 东宁县| 伊春市| 河曲县| 宝山区| 靖远县| 辉县市| 漳浦县| 乐都县| 苗栗市| 山丹县| 永平县|