我正在使用Hibernate 4.1.0.Final和Spring 3.1.1。
当我进行junit测试时,出现以下异常
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory' defined in class path resource [spring-
context.xml]: Invocation of init method failed; nested exception is
org.hibernate.MappingException: Could not determine type for:
test.entity.Employees,at table: PROJECT, for columns:
[org.hibernate.mapping.Column(employees)]
项目实体类
@Entity
@Table(name = "PROJECT")
public class Project {
@OneToOne
@JoinColumn(name="EMP_NUMBER")
private Employees employees;
.....
员工实体类
@Entity
@Table(name = "EMPLOYEES")
public class Employees {
private String employeeNo;
@Id
@Column(name = "EMP_NUMBER")
public String getEmployeeNo() {
return employeeNo;
}
public void setEmployeeNo(String employeeNo) {
this.employeeNo = employeeNo;
}
朱尼特
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:spring-context.xml")
@TransactionConfiguration(defaultRollback=true,transactionManager="transactionManager")
public class ProjectTest {
@Autowired
private ProjectDAO projectDAO;
@Test
public void testProjectId() {
Project project = projectDAO.findProjectId(1L);
assertNotNull(project);
}
}