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;
	}
}

  

猜你喜欢

转载自chenjumin.iteye.com/blog/1090278