首页 > 解决方案 > org.hibernate.AnnotationException:@OneToOne on com.abc.dto.Test.name 引用了一个未知实体:com.abc.type.TestName

问题描述

我有一个实体引用了另一个失败的实体。使用 Spring-beans-5.0.9.RELEASE.jar
spring-boot: 2.0.5
spring form: 5.0.9

package com.abc.dto

@Entity
@Table(name="Test_Table")
@SequenceGenerator(name="seq",sequenceName="TEST_SEQUENCE")
public class Test {

private TestName name;

@JoinColumn
@OneToOne(fetch=FetchType.LAZY)
public TestName getName(return name);
}

错误:org.hibernate.AnnotationException:@OneToOne on com.abc.dto.Test.name 引用了一个未知实体:com.abc.type.TestName

com.abc.type.TestName 是 jar 的一部分

package com.abc.type
@Entity
@Table(name="Test_name")
public class TestName{
//code
}

标签: javaspring-boothibernatejpa

解决方案


这很可能是由于未正确扫描包或未在 persistence.xml 或 orm.xml 中声明新实体。请参阅https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/domain/EntityScan.html


推荐阅读