java - java.lang.IllegalArgumentException:不是托管类型:classTestEntity
问题描述
我正在尝试使用 Spring JPA 从数据库中的两个表中获取数据:
并且有一个例外:
nested exception is java.lang.IllegalArgumentException: Not an managed type: class com.entity.Product
产品实体是:
@Entity
@Table(name = "PRODUCT")
@Getter
@Setter
public class Product {
@Id
@Column(name = "id", unique = true, nullable = false)
private int id;
@Column(name = "name")
private String name;
@OneToMany(mappedBy = "productService", fetch = FetchType.EAGER)
private List<ProductService> productService;
@ManyToOne(targetEntity = ProductStatus.class, optional = false)
@JoinColumn(name = "PRODUCT_STATUS_ID")
private ProductStatus status;
}
存储库是
public interface CaKeyRepository extends JpaRepository<Product, Integer> {
}
尝试使用 findAll() 加载;
public HashMap<String, Key> loadProduct() throws Exception {
List<Product> products = caKeyRepository.findAll();
我也使用 WildFly 12 应用程序服务器。
使用依赖项实现项目:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-hibernate4</artifactId>
</dependency>
都提供
- 春季版 - 4.3.10.RELEASE
- Spring 数据版本 - 1.11.6.RELEASE
- Hibernate-entitymanager 版本 - 4.3.11.Final
- Hibernate-validator 版本 - 5.1.3.Final
- Atomikos 版本 - 4.0.4
解决方案
看起来你的实体没有被休眠扫描。
如果您通过 persistence.xml 配置了 JPA/Hibernate: <class>com.entity.Product</class>
如果通过 Spring-ORM,那么在您的LocalContainerEntityManagerFactoryBean中设置packagesToScan
方法中的包。
推荐阅读
- c - OpenGL中的glColor3f亮度很小
- db2 - DB2 SYSADM Windows - 没有运气
- javascript - 如何消除 React Table 下拉列表中的重复值 - ReactJS/JavaScript
- macos - 使用 Image Magick 创建具有图层支持的图像
- python - 从 Jupyter 停止 Flask 服务器
- translation - 谷歌翻译不支持的语言
- git - 将删除和添加的文件夹更正为历史上很久以前发生的重命名
- javascript - 如何在 sequelize 中对嵌套属性进行分组?
- javascript - 正则表达式从字符串获取对象参数并从 JSON/Js 对象获取这些参数的值
- python - TypeError:不支持的操作数类型/:'Image'和'int'