java - 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
}
解决方案
这很可能是由于未正确扫描包或未在 persistence.xml 或 orm.xml 中声明新实体。请参阅https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/domain/EntityScan.html
推荐阅读
- java - 使用 eureka 和 zuul 的 spring boot 企业应用程序
- api - 响应状态码不表示成功:404(未找到)
- string - Bigquery SQL - 条件字符串 agg
- powerbi - 如何从另一个 Power BI 表中获取信息
- python - 为什么我的属性值不能正确打印到 Django 中的 shell?
- javascript - 如何将自定义键值分配给数组?
- javascript - 在 ajax 函数中使用 setInterval 返回“toLowerCase”错误
- javascript - forEach 推最后一个参数
- android - android:drawableLeft 在 api 级别 < 21 中不起作用
- python - 如何在 Pandas 中创建索引列名和循环?