我正在尝试使用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>
全部提供
答案 0 :(得分:0)
好像您的实体没有被休眠扫描。
如果您通过persistence.xml配置了JPA /休眠:<class>com.entity.Product</class>
如果通过Spring-ORM,则在您的LocalContainerEntityManagerFactoryBean中使用packagesToScan
方法设置包。