0

I'm trying to get data using Spring JPA from two table in database:

enter image description here

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();

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

Also I use the WildFly 12 application server.

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
  • Spring data version - 1.11.6.RELEASE
  • Hibernate-entitymanager version - 4.3.11.Final
  • Hibernate-validator version - 5.1.3.Final
  • Atomikos version - 4.0.4
JimHawkins
  • 4,843
  • 8
  • 35
  • 55
Vadim
  • 557
  • 8
  • 21

1 Answers1

0

Look like your entity is not scanned by hibernate.

If you configured JPA/Hibernate through persistence.xml: <class>com.entity.Product</class>

if through Spring-ORM then in your LocalContainerEntityManagerFactoryBean set the package in the packagesToScan method.

JEY
  • 6,973
  • 1
  • 36
  • 51
Robert Niestroj
  • 15,299
  • 14
  • 76
  • 119