hibernate一对一外键关联

阅读更多

一、创建实体类

 

package com.wr.hibernate.entity;

public class Department {

	private int deptId;
	private String deptName;
	private Manager mgr;

	public int getDeptId() {
		return deptId;
	}

	public Manager getMgr() {
		return mgr;
	}

	public void setMgr(Manager mgr) {
		this.mgr = mgr;
	}

	public void setDeptId(int deptId) {
		this.deptId = deptId;
	}

	public String getDeptName() {
		return deptName;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	@Override
	public String toString() {
		return "Department [deptId=" + deptId + ", deptName=" + deptName + "]";
	}

}

 

package com.wr.hibernate.entity;

public class Manager {

	private int mgrId;
	private String mgrName;
	private Department dept;

	public int getMgrId() {
		return mgrId;
	}

	public void setMgrId(int mgrId) {
		this.mgrId = mgrId;
	}

	public String getMgrName() {
		return mgrName;
	}

	public void setMgrName(String mgrName) {
		this.mgrName = mgrName;
	}

	public Department getDept() {
		return dept;
	}

	public void setDept(Department dept) {
		this.dept = dept;
	}

	@Override
	public String toString() {
		return "Manager [mgrId=" + mgrId + ", mgrName=" + mgrName + ", dept=" + dept + "]";
	}

}

 

二、创建POJO映射文件

 






	

		
			
			
		

		
			
		
		
		
			
		
		
		
	


 






	

		
			
			
		

		
			
		
		
		
		

	


 

你可能感兴趣的:(hibernate,java,ORM)