java - 使用 Spring 和 JPA,获取 java.lang.IllegalArgumentException : Unknown entity

标签 java hibernate spring-boot spring-data spring-batch

所以我一直在尝试让这个应用程序利用 Spring 4、Spring Boot 1.4 和 Hibernate 5 工作(通过检查 Maven 中的 Maven 依赖项进行验证,但无论出于何种原因,它都不会确认我的设置以查找位置)对于特定包中的实体类,而是在一个完全不同的包中查找,但我找不到指定它的位置。使用 javax.persistence pacakge 而不是 org.hibernate 之类的步骤没有结果。还使用 SessionFactory 而不是 EntityManager产生了同样的错误。没有使用 persistence.xml (或者实际上任何 xml,如使用 Spring 3,我想要一个完全基于 Java 的配置,并且根据研究,这应该是可能的?

言归正传,这是当前的代码。

POM 文件:

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <spring.boot.version>1.4.2.RELEASE</spring.boot.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring.boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-file</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

    <!-- Other -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.2</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.40</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

实体类:

@Entity
@Table(name = "inventory")
public class InventoryDBModel implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "product_id")
    private int productID;

    @Id
    @Column(name = "store_id")
    private int storeID;

    @Column(name = "quantity")
    private int quantity;

    @Column(name = "reported_on")
    private String reportedOn; //Convert to Date

    @Column(name = "updated_at")
    private String updatedAt; //Convert to Date

    public int getProductID() {
        return productID;
    }

    public int getStoreID() {
        return storeID;
    }

    public int getQuantity() {
        return quantity;
    }

    public String getReportedOn() {
        return reportedOn;
    }

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setProductID(final int productID) {
        this.productID = productID;
    }

    public void setStoreID(final int storeID) {
        this.storeID = storeID;
    }

    public void setQuantity(final int quantity) {
        this.quantity = quantity;
    }

    public void setReportedOn(final String reportedOn) {
        this.reportedOn = reportedOn;
    }

    public void setUpdatedAt(final String updatedAt) {
        this.updatedAt = updatedAt;
    }
}

DAO 接口(interface):

public interface InventoryDAO {
    public void createOne(LCBOInventory lcboInventory);

    public void createMany(List<? extends LCBOInventory> lcboInventorysItems);

    public void delete(int productID, int styleID);

    public List<LCBOInventory> getByProduct(int productID);

    public LCBOInventory getByProductAndStore(int productID, int storeID);

    public List<LCBOInventory> getByStore(int storeID);

    public List<LCBOInventory> list();

    public void updateOne(LCBOInventory lcboInventory);

    public void updateMany(List<LCBOInventory> lcboInventoryItems); 
}

DAO 实现类:

public class InventoryDAOImpl implements InventoryDAO {

    static final String SELECT_INVENTORY = "SELECT i FROM inventory ";
    static final String PRODUCTID = "productID";
    static final String STOREID = "storeID";

    @Autowired
    private EntityManager em;

    public InventoryDAOImpl() {
         //basic constructor
    }

    public InventoryDAOImpl(final EntityManager em) {
        this.em = em;
    }

    @Override
    @Transactional
    public void createOne(final LCBOInventory newLCBOInventoryItem) {
        LCBOInventory lcboInventoryObject = new LCBOInventory();

        lcboInventoryObject.setProductID(newLCBOInventoryItem.getProductID());
        lcboInventoryObject.setQuantity(newLCBOInventoryItem.getQuantity());
        lcboInventoryObject.setReportedOn(newLCBOInventoryItem.getReportedOn());
        lcboInventoryObject.setStoreID(newLCBOInventoryItem.getStoreID());
        lcboInventoryObject.setUpdatedAt(newLCBOInventoryItem.getUpdatedAt());

        em.persist(lcboInventoryObject);
    }

    @Override
    @Transactional
    public void createMany(final List<? extends LCBOInventory> lcboInventorysItems) {       
        lcboInventorysItems.stream().forEach((currentInventoryItem) -> {
            LCBOInventory lcboInventoryObject = new LCBOInventory();

            lcboInventoryObject.setProductID(currentInventoryItem.getProductID());
            lcboInventoryObject.setQuantity(currentInventoryItem.getQuantity());
            lcboInventoryObject.setReportedOn(currentInventoryItem.getReportedOn());
            lcboInventoryObject.setStoreID(currentInventoryItem.getStoreID());
            lcboInventoryObject.setUpdatedAt(currentInventoryItem.getUpdatedAt());

            em.persist(lcboInventoryObject);
        }); 
    }

    @Override
    public void delete(final int productID, final int styleID) {
        Query loadSpecificProductStoreCombo = em.createQuery("DELETE i FROM inventory i WHERE i.productID = :productID AND i.storeID = :storeID");

        loadSpecificProductStoreCombo.setParameter("productID", productID);
        loadSpecificProductStoreCombo.setParameter("storeID", styleID);

        loadSpecificProductStoreCombo.executeUpdate();
    }

    @Override
    public List<LCBOInventory> getByProduct(final int productID) {
        TypedQuery<LCBOInventory> loadInventoryByProduct = em.createQuery(SELECT_INVENTORY + "WHERE i.productID = :productID " +
                                                                            "AND i.storeID = :storeID", LCBOInventory.class);

        loadInventoryByProduct.setParameter("productID", productID);

        return loadInventoryByProduct.getResultList();
    }

    @Override
    public LCBOInventory getByProductAndStore(final int productID, final int storeID) {
        TypedQuery<LCBOInventory> loadSpecificProductStoreCombo = em.createQuery(SELECT_INVENTORY + "WHERE i.productID = :productID " +
                                                                                    "AND i.storeID = :storeID", LCBOInventory.class);

        loadSpecificProductStoreCombo.setParameter("productID", productID);
        loadSpecificProductStoreCombo.setParameter("storeID", storeID);

        return loadSpecificProductStoreCombo.getSingleResult();
    }

    @Override
    public List<LCBOInventory> getByStore(final int storeID) {
        TypedQuery<LCBOInventory> loadInventoryByStore = em.createQuery(SELECT_INVENTORY + "WHERE i.productID = :productID " +
                                                                            "AND i.storeID = :storeID", LCBOInventory.class);

        loadInventoryByStore.setParameter("storeID", storeID);

        return loadInventoryByStore.getResultList();
    }

    @Override
    public List<LCBOInventory> list() {
        return em.createQuery("SELECT i FROM product i", LCBOInventory.class).getResultList();
    }

    @Override
    @Transactional
    public void updateOne(final LCBOInventory newLCBOInventoryItem) {
        TypedQuery<LCBOInventory> loadSpecificProductStoreCombo = em.createQuery(SELECT_INVENTORY + "WHERE i.productID = :productID " +
                                                                                    "AND i.storeID = :storeID", LCBOInventory.class);

        loadSpecificProductStoreCombo.setParameter("productID", newLCBOInventoryItem.getProductID());
        loadSpecificProductStoreCombo.setParameter("storeID", newLCBOInventoryItem.getStoreID());

        LCBOInventory oldLCBOInventoryItem = loadSpecificProductStoreCombo.getSingleResult();

        oldLCBOInventoryItem.setProductID(newLCBOInventoryItem.getProductID());
        oldLCBOInventoryItem.setQuantity(newLCBOInventoryItem.getQuantity());
        oldLCBOInventoryItem.setReportedOn(newLCBOInventoryItem.getReportedOn());
        oldLCBOInventoryItem.setStoreID(newLCBOInventoryItem.getStoreID());
        oldLCBOInventoryItem.setUpdatedAt(newLCBOInventoryItem.getUpdatedAt());
    }

    @Override
    public void updateMany(List<LCBOInventory> lcboInventoryItems) {
        // TODO Auto-generated method stub

    }

数据库配置类:

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages="com.sample.hibernate.model")
public class DatabaseConfig {

    @Autowired
    private LCBOInventoryTrackerProperties properties;

    @Bean(name = "entityManager")
    public EntityManagerFactory entityManagerFactory() throws SQLException {

        final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
        factoryBean.setDataSource(dataSource());
        factoryBean.setJpaDialect(new HibernateJpaDialect());
        factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        factoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); 
        factoryBean.setPersistenceUnitName("persistenceUnit");
        factoryBean.setJpaProperties(getHibernateProperties());
        factoryBean.setPackagesToScan(new String[]{"com.sample.hibernate.model"}); 
        factoryBean.afterPropertiesSet();

        return factoryBean.getObject();
    }

    @Bean
    public DataSource dataSource() throws SQLException {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();

        dataSource.setDriverClassName(properties.getDb().getDriver());
        dataSource.setUrl(properties.getDb().getUrl());
        dataSource.setUsername(properties.getDb().getUsername());
        dataSource.setPassword(properties.getDb().getPassword());

        return dataSource;
    }

    private Properties getHibernateProperties() {
        Properties hibernateConfigProperties = new Properties();

        hibernateConfigProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
        hibernateConfigProperties.put("hibernate.show_sql", true);
        hibernateConfigProperties.put("hibernate.generate_statistics", true);
        hibernateConfigProperties.put("hibernate.hbm2ddl.auto", "update");
        hibernateConfigProperties.put("hibernate.use_sql_comments", true);

        return hibernateConfigProperties;
    }

    @Bean
    public PlatformTransactionManager transactionManager() throws SQLException{
       JpaTransactionManager transactionManager = new JpaTransactionManager();
       transactionManager.setEntityManagerFactory(this.entityManagerFactory());

       return transactionManager;
    }

    @Bean
    public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
       return new PersistenceExceptionTranslationPostProcessor();
    }

    //DAO Autowires

    @Autowired
    @Bean(name = "inventoryDAO")
    public InventoryDAO getInventoryDAO(final EntityManager entityManager) {
        return new InventoryDAOImpl(entityManager);
    }

最后但并非最不重要的一点是堆栈跟踪。

java.lang.IllegalArgumentException: Unknown entity: com.sample.lcbo.domain.LCBOInventory
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1149) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_92]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_92]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_92]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_92]
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:347) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at com.sun.proxy.$Proxy60.persist(Unknown Source) ~[na:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_92]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_92]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_92]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_92]
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:298) ~[spring-orm-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at com.sun.proxy.$Proxy60.persist(Unknown Source) ~[na:na]
    at com.sample.lcbo.dao.InventoryDAOImpl.lambda$0(InventoryDAOImpl.java:56) ~[classes/:na]
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source) ~[na:1.8.0_92]
    at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source) ~[na:1.8.0_92]
    at com.sample.lcbo.dao.InventoryDAOImpl.createMany(InventoryDAOImpl.java:47) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_92]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_92]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_92]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_92]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at com.sun.proxy.$Proxy62.createMany(Unknown Source) ~[na:na]
    at com.sample.lcbo.writer.LCBOInventoryWriter.write(LCBOInventoryWriter.java:20) ~[classes/:na]
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:274) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) ~[spring-batch-infrastructure-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200) ~[spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:392) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_92]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_92]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_92]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_92]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) [spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at com.sun.proxy.$Proxy65.run(Unknown Source) [na:na]
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:216) [spring-boot-autoconfigure-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:233) [spring-boot-autoconfigure-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:125) [spring-boot-autoconfigure-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:119) [spring-boot-autoconfigure-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:800) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:784) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:771) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at com.sample.lcbo.config.LCBOBatchConfig.main(LCBOBatchConfig.java:69) [classes/:na]

对此有任何帮助,我将不胜感激。虽然我已尽力尽可能地详细说明,但如果有任何问题,请直接询问,我会尽力提供。

最佳答案

重要的是,自 Spring 3.1 起,可以使用 persistence.xml 免费方法。请参阅文档 here .

此外,您应该知道 Spring Boot 1.4 需要 Spring Framework 4.3。请参阅release notes其中。

你看到官方Spring指南了吗Accessing Data with JPA

更新#1

您正在尝试使用实体com.sample.lcbo.domain.LCBOInventory(请参阅异常详细信息),但您将com.sample.hibernate.model设置为EntityManagerFactoryBean.setPackagesToScan方法。

关于java - 使用 Spring 和 JPA,获取 java.lang.IllegalArgumentException : Unknown entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41323656/

相关文章:

java - 如何使用 do while 循环将用户输入转换为星号?

JavaEE : Does EntityManager get method changing state in DB

java - hibernate 不会创建 hbm2ddl.auto 设置为 "update"的中间表

java - Hibernate级联删除依赖实体(ManyToOne OneToMany)

java - 寻找在 Spring MVC 中显示计数的更好方法

java - 如何使用 Spring Integration 2.0.5 根据内容路由消息?

java - 如何在不使用第三个多模块 Maven 项目的情况下自动从命令行构建主 Maven 项目之前构建项目依赖关系?

java - SpringBoot 可能存在重定向过滤问题

Hibernate 注释或 XML 配置

spring-boot - springboot从1.5.x升级到2.3.x后如何保留旧的执行器端点