注解:配置实体类,并在spring配置文件中配置

1.jar包

hibernate-annotations.jar
hibernate-commons-annotations.jar

2.注解配置的实体类Emp

package entity;

import java.util.Date;
import javax.persistence.*;

@Entity
@Table(name = "EMP")
@NamedQuery(name = "selectEmp", query = "from Emp where empName like :ename")
public class Emp implements java.io.Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_emp1")
	@SequenceGenerator(name = "seq_emp1", sequenceName = "seq_emp", allocationSize = 1, initialValue = 1)
	private int empNo;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "DEPTNO")
	private Dept dept;
	@Column(name = "ENAME")
	private String empName;
	@Column(name = "HIREDATE")
	private Date hiredate;
	@Transient
	private String job;
	@Transient
	private Short mgr;
	@Transient
	private Double salary;
	@Transient
	private Double comm;

	public Emp() {
	}

	public Emp(Short empNo, String empName) {
		super();
		this.empNo = empNo;
		this.empName = empName;
	}

	public int getEmpNo() {
		return empNo;
	}

	public void setEmpNo(int empNo) {
		this.empNo = empNo;
	}

	public Dept getDept() {
		return dept;
	}

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

	public String getEmpName() {
		return empName;
	}

	public void setEmpName(String empName) {
		this.empName = empName;
	}

	public String getJob() {
		return job;
	}

	public void setJob(String job) {
		this.job = job;
	}

	public Short getMgr() {
		return mgr;
	}

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

	public Date getHiredate() {
		return hiredate;
	}

	public void setHiredate(Date hiredate) {
		this.hiredate = hiredate;
	}

	public Double getSalary() {
		return salary;
	}

	public void setSalary(Double salary) {
		this.salary = salary;
	}

	public Double getComm() {
		return comm;
	}

	public void setComm(Double comm) {
		this.comm = comm;
	}
}

3.更改spring配置





	
	
	
	
	
	
	
	
		
			classpath:jdbc.properties
		
		
		
		
		
		
		
		
		

		
		
			
			
				
					
						org.hibernate.dialect.Oracle9Dialect
					
					
						jdbc:oracle:thin:@localhost:1521:orcl
					
					
						true
					
					
						true
					
				
			
//配置注解实体类
			
			
			entity.Emp
			entity.Dept
			
			
			
			
		
		
		
			
		

		
			
		

		
			
		
		
		
			
		
		
		
			
				
				
				
				
				
				
				
				
			

		
		
		
			
			
		

注解:配置实体类,并在spring配置文件中配置_第1张图片

你可能感兴趣的:(注解:配置实体类,并在spring配置文件中配置)