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

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:

主站蜘蛛池模板: 黑龙江省| 巴青县| 金坛市| 蓬溪县| 易门县| 黔西县| 清丰县| 广灵县| 焉耆| 北宁市| 竹山县| 临颍县| 潜江市| 宕昌县| 青岛市| 吴川市| 丹凤县| 兴义市| 沁阳市| 祁门县| 惠东县| 介休市| 板桥市| 始兴县| 江都市| 长岛县| 石柱| 昌黎县| 方正县| 眉山市| 邳州市| 武川县| 崇信县| 通榆县| 镇宁| 同仁县| 龙江县| 海淀区| 永年县| 保靖县| 桐梓县|