尝试从HQL查询创建一个对象,但是我无法弄清楚我做错了什么:(Spring 3.1.1)如何返回Java类,或者至少返回类或实体?< / p>
public Employee findEmployeeById(int id){
String sql = "SELECT * FROM schema.Employee WHERE ID = ?";
Employee employee = (Employee)getJdbcTemplate().queryForObject(
sql, new Object[] { id },new BeanPropertyRowMapper(Employee.class));
return employee;
}
Employee.java
@Entity
@Table(name="schema.Employee")
public class Employee {
@Id
@GeneratedValue
@Column(name="ID")
private Integer id;
@Column(name="NAME")
private String name;
@ManyToOne
@JoinColumn(name = "DEPARTMENT_ID")
private Department department;
// Accessors
}
Department.Java
@Entity
@Table(name="schema.DEPARTMENT")
public class Department {
@Id
@GeneratedValue
@Column(name="DEPARTMENT_ID")
private Long departmentId;
@Column(name="DEPT_NAME")
private String departmentName;
@OneToMany(mappedBy="department")
private Set<employee> employees;
// Getter and Setter methods
}