天天看點

JPA各種字段的映射

@Entity

@Table(name="person")

public class Person {

 @Id @GeneratedValue  //不寫是采用預設政策,即:(Strategy=Generation.AUTO)

 private Integer id;  //主鍵且資料庫是mysql就自動增長(identified),是Oracle就序列化(sequence)

 @Column(length=10, nullable=false)  //長度為10,且不能為空

 private String name;

 @Temporal(TemporalType.DATE)  //日期類型

 private Date birthday;

 @Lob    //長整型,對應到mysql資料庫為LongText

 private String info;

 @Lob @Basic(fetch=FetchType.LAZY)  //二進制資料,且延遲加載

 private Byte[] file;

 @Enumerated(EnumType.STRING) @Column(length=5,nullable=false) //枚舉類型,且将值存入資料庫

 private Gender gender= Gender.MAN;

 @Transient   //不映射進資料庫

 private String p_w_picpathpath;

}

繼續閱讀