概述
@Entity@Table(name="person")
public class Person{
@ID //标识为主键
@GenereateValue//主键生产策略 默认自动auto
private Integer id;
@Temporal(TemporalType.DATE)//指明为date类型
private Date birthday;
private String name;
@Enumerated(EnumType.STRING) @Column(length=5,nullable=false)//EnumType.STRING指明存字符串,可以指定存索引
private Gender gender=Gender.MAN;
@Lob//大文本存储。。数据库存储类型为LONGTEXT
public String info;
@Basic(fetch=FetchType.lazy)//存储二进制 延迟加载内容 一般大数据的话都要延迟加载不然浪费内存@Basic(fetch=FetchType.Eager)//(立刻加载)//必须session要打开,或者entityManager要打开
public Byte[] file;
@Transient//不跟数据库表做映射 就是表中没有这个字段
private String imagepath;
get/set mothod is ignore;
//
}
public enum Gender{
MAN,WOMEN
}
原帖地址: http://blog.sina.com.cn/s/blog_534f69a0010139hn.html
最后
以上就是彩色香菇为你收集整理的JPA 实体字段映射(时间,枚举,延迟加载,@transient)的全部内容,希望文章能够帮你解决JPA 实体字段映射(时间,枚举,延迟加载,@transient)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复