简体   繁体   English

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

[英]java.lang.IllegalArgumentException: Not an managed type: classTestEntity

I'm trying to get data using Spring JPA from two table in database: 我正在尝试使用Spring JPA从数据库的两个表中获取数据:

在此处输入图片说明

And have the exception: 并有例外:

nested exception is java.lang.IllegalArgumentException: Not an managed type: class com.entity.Product

Product entity is: 产品实体为:

@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;
}

Repository is 储存库为

public interface CaKeyRepository extends JpaRepository<Product, Integer> {

}

Trying to load with findAll(); 尝试加载findAll();

public HashMap<String, Key> loadProduct() throws Exception {
    List<Product> products = caKeyRepository.findAll();

Also I use the WildFly 12 application server. 我也使用WildFly 12应用程序服务器。

Implementing to project with dependencies: 实现具有依赖项的项目:

    <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>

All are provided 全部提供

  • Spring version - 4.3.10.RELEASE 春季版-4.3.10.RELEASE
  • Spring data version - 1.11.6.RELEASE Spring数据版本-1.11.6.RELEASE
  • Hibernate-entitymanager version - 4.3.11.Final Hibernate-entitymanager版本-4.3.11.Final
  • Hibernate-validator version - 5.1.3.Final Hibernate-validator版本-5.1.3。最终
  • Atomikos version - 4.0.4 Atomikos版本-4.0.4

Look like your entity is not scanned by hibernate. 看来您的实体没有被休眠扫描。

If you configured JPA/Hibernate through persistence.xml: <class>com.entity.Product</class> 如果您通过persistence.xml配置了JPA / Hibernate: <class>com.entity.Product</class>

if through Spring-ORM then in your LocalContainerEntityManagerFactoryBean set the package in the packagesToScan method. 如果通过Spring-ORM,则在您的LocalContainerEntityManagerFactoryBean中,在packagesToScan方法中设置包。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalArgumentException问题:不是托管类型 - Problem with java.lang.IllegalArgumentException: Not a managed type java.lang.IllegalArgumentException:不是托管类型: - java.lang.IllegalArgumentException: Not a managed type: java.lang.IllegalArgumentException:不是托管类型:class - java.lang.IllegalArgumentException: Not a managed type: class java.lang.IllegalArgumentException:在Spring Boot应用程序中不是托管类型 - java.lang.IllegalArgumentException: Not a managed type in spring boot app spring-data-solr java.lang.IllegalArgumentException:不是托管类型 - spring-data-solr java.lang.IllegalArgumentException: Not a managed type java.lang.IllegalArgumentException:不是托管类型 - Spring Boot 中的多个数据库 - java.lang.IllegalArgumentException: Not a managed type - Multiple Databases in Spring Boot Spring Boot 异常“java.lang.IllegalArgumentException:不是托管类型:” - Spring Boot exception "java.lang.IllegalArgumentException: Not a managed type:" java.lang.IllegalArgumentException:不是托管类型:class models.User - java.lang.IllegalArgumentException: Not a managed type: class models.User 春季-AWS(无春季启动):java.lang.IllegalArgumentException:不是托管类型 - Spring - AWS (no spring boot): java.lang.IllegalArgumentException: Not a managed type java.lang.IllegalArgumentException:来自托管类型[T]的属性[A]不存在 - java.lang.IllegalArgumentException: The attribute [A] from the managed type [T] is not present
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM