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

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:

主站蜘蛛池模板: 翁牛特旗| 河东区| 读书| 苍溪县| 江津市| 兖州市| 大同县| 平果县| 崇礼县| 平顶山市| 庆安县| 于田县| 东港市| 铁岭市| 响水县| 阿拉善左旗| 金秀| 正镶白旗| 大同县| 青岛市| 潍坊市| 和平区| 新丰县| 奉新县| 达拉特旗| 张家界市| 长宁区| 信阳市| 霍城县| 凤冈县| 延寿县| 莱西市| 尚义县| 桐城市| 施甸县| 宜春市| 靖远县| 香港| 阿巴嘎旗| 抚松县| 平乡县|