【发布时间】:2019-04-28 05:39:07
【问题描述】:
我正在尝试使用 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
【问题讨论】:
-
为什么
Product的id类型是DECIMAL在你的d 中?
标签: java hibernate spring-data-jpa wildfly