0

Spring 3.1.1でHibernate 4.1.0.Finalを使用しています。

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

1 に答える 1

1

このブログは、一方向の @OneToOne アソシエーションをセットアップするのに役立つかもしれません!

于 2013-07-06T14:30:33.087 に答える