JPA注解配置实例

以下收集了一些JPA常用的注解实例:

@Entity  
@Table(name="ACCOUNT_INFO")
public class ManagerAccountInfo implements Serializable {
private static final long serialVersionUID = -1021341410178291401L;

private Long id;
private String loginAccount;
private Date lastLoginDate;
private ManagerOperator managerOperator;
private Set<FrameworkAccountLevel> frameworkAccountLevels;
private String officeNo;

//标识字段
@Id
@GeneratedValue(generator = "Cjm-Generator")
@GenericGenerator(name = "Cjm-Generator", strategy = "com.cjm.core.utils.IdGenerator")
@Column(name="id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}

//普通字段
@Column(name = "LOGIN_ACCOUNT")
public String getLoginAccount() {
return this.loginAccount;
}
public void setLoginAccount(String loginAccount) {
this.loginAccount = loginAccount;
}

//日期字段
@Temporal(TemporalType.DATE)
@Column(name = "LAST_LOGIN_DATE")
public Date getLastLoginDate() {
return this.lastLoginDate;
}
public void setLastLoginDate(Date lastLoginDate) {
this.lastLoginDate = lastLoginDate;
}

//多对一
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MO_ID", referencedColumnName = "MO_ID")
public ManagerOperator getManagerOperator() {
return this.managerOperator;
}
public void setManagerOperator(ManagerOperator managerOperator) {
this.managerOperator = managerOperator;
}

//一对多
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "managerAccountInfo")
public Set<FrameworkAccountLevel> getFrameworkAccountLevels() {
return this.frameworkAccountLevels;
}
public void setFrameworkAccountLevels(
Set<FrameworkAccountLevel> frameworkAccountLevels) {
this.frameworkAccountLevels = frameworkAccountLevels;
}

//非持久化字段
@Transient
public String getOfficeNo() {
return officeNo;
}
public void setOfficeNo(String officeNo) {
this.officeNo = officeNo;
}
}

?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值