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

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:

主站蜘蛛池模板: 永顺县| 介休市| 房山区| 马公市| 宜君县| 盖州市| 德惠市| 周宁县| 仲巴县| 琼结县| 潼关县| 水城县| 巴中市| 陆丰市| 双峰县| 白城市| 贡觉县| 荔浦县| 富锦市| 商水县| 大厂| 玉山县| 阿合奇县| 城口县| 桃园市| 阿拉善右旗| 太保市| 宜兰市| 昌图县| 绥阳县| 宜城市| 临潭县| 蛟河市| 成安县| 日土县| 青川县| 丘北县| 股票| 兰西县| 奎屯市| 惠水县|