使用Spring& JPA,获取java.lang.IllegalArgumentException:未知实体

时间:2016-12-25 18:43:37

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

所以我一直在尝试使用Spring 4,Spring Boot 1.4和Hibernate 5来运行这个应用程序(通过检查Maven中的maven依赖关系来验证,但无论出于何种原因,它都不会确认我的设置在哪里查看对于特定包中的Entity类,而是查看一个完全不同的包,我找不到它所指定的位置。使用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界面:

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]

对此有任何帮助,我非常感谢。尽管我尽力做到最好,但如果有任何问题,请提出要求,我会尝试提供。

1 个答案:

答案 0 :(得分:2)

重要的是,从Spring 3.1开始,persistence.xml免费方法是可行的。请参阅文档here

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

您是否看到官方春季指南Accessing Data with JPA

更新#1

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