【问题标题】:Caused by: org.hibernate.MappingException: Could not determine type for: Employees [org.hibernate.mapping.Column(employees)]原因:org.hibernate.MappingException:无法确定类型:员工 [org.hibernate.mapping.Column(employees)]
【发布时间】:2013-07-04 12:46:11
【问题描述】:

我正在使用 Hibernate 4.1.0.FinalSpring 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); 
    } 
}

【问题讨论】:

  • 我们需要您的代码测试来审核。你把它放在哪里 confi.xml?
  • 我已经在我的问题中发布了我的 junit 测试代码。我是spring-context.xml,位于appContext 文件夹中。

标签: spring hibernate jpa junit jpa-2.0


【解决方案1】:

This blog 可能会帮助您建立单向@OneToOne 关联!

【讨论】:

    猜你喜欢
    • 2016-08-28
    • 1970-01-01
    • 2018-03-08
    • 2013-03-28
    • 2016-06-05
    • 2011-04-16
    • 2016-06-23
    • 2016-10-04
    • 1970-01-01
    相关资源
    最近更新 更多