簡體   English   中英

java.lang.IllegalArgumentException:不是托管類型:classTestEntity

[英]java.lang.IllegalArgumentException: Not an managed type: 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。最終
  • Atomikos版本-4.0.4

看來您的實體沒有被休眠掃描。

如果您通過persistence.xml配置了JPA / Hibernate: <class>com.entity.Product</class>

如果通過Spring-ORM,則在您的LocalContainerEntityManagerFactoryBean中,在packagesToScan方法中設置包。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM