java.lang.IllegalArgumentException:不是实体

问题描述 投票:0回答:1

我正在遵循在线教程,但遇到了一个我无法解决的错误。我有一个多模块 Quarkus 应用程序。一个模块称为“Customer”,具有相应的 Customer 类,该类被注释为 @Entity:

package org.agoncal.quarkus.jpa;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import java.time.Instant;

@Entity
public class Customer {
    @Id
    @GeneratedValue
    public Long id;

    public String firstName;
...

在另一个模块“vintage-store”中,创建了 customerRepository,看起来像这样:

package org.agoncal.quarkus.panache.repository;

import io.quarkus.hibernate.orm.panache.PanacheRepository;
import org.agoncal.quarkus.jpa.Customer;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class CustomerRepository implements PanacheRepository<Customer> {}

现在,当我尝试在古董商店上运行

mvn clean install
时,CustomerRepositoryTest 文件中的测试失败了:

package org.agoncal.quarkus.panache.repository;

import io.quarkus.test.TestTransaction;
import io.quarkus.test.junit.QuarkusTest;
import org.agoncal.quarkus.jpa.Customer;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;
import java.sql.SQLException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@QuarkusTest
public class CustomerRepositoryTest {
    @Inject
    CustomerRepository repository;

    @Test
    @TestTransaction
    public void shouldCreateAndFindCustomer() throws SQLException {
        Customer customer = new Customer("first name", "last name", "email");

        repository.persist(customer);
        assertNotNull(customer.getId());

        Customer foundCustomer = repository.findById(customer.getId());
        assertEquals("first name", foundCustomer.getFirstName());

    }

}

出现以下错误消息:

java.lang.IllegalArgumentException: Not an entity [class org.agoncal.quarkus.jpa.Customer]
        at org.agoncal.quarkus.panache.repository.CustomerRepositoryTest.shouldCreateAndFindCustomer(CustomerRepositoryTest.java:24)
Caused by: org.hibernate.MappingException: Unknown entity: org.agoncal.quarkus.jpa.Customer
        at org.agoncal.quarkus.panache.repository.CustomerRepositoryTest.shouldCreateAndFindCustomer(CustomerRepositoryTest.java:24)

我已经看了几个小时了,但没有发现问题。我发现了一些提示,它可能与 jakarta 和 javax 之间的差异有关,但不确定。

java pom.xml quarkus quarkus-panache
1个回答
0
投票

检查您的持久性配置,如果它包含您的“客户”的包和类。

© www.soinside.com 2019 - 2024. All rights reserved.