Spring启动应用程序无法插入数据

时间:2016-07-27 02:09:53

标签: spring spring-boot h2

我只是想在https://www.youtube.com/watch?v=p8AdyMlpmPk链接之后创建一个基本的Spring Boot应用程序。我按照指导做了一切。但我不确定为什么数据没有插入表中。在编写插入查询时是否必须使用类名?请查看data.sql文件。我认为sql语句中有错误。我只是想不通。请看看。

应用

package com.example;

import java.util.Collection;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;

@SpringBootApplication
public class BookingManagementApplication {

    public static void main(String[] args) {
        SpringApplication.run(BookingManagementApplication.class, args);
    }
}

@Component
class BookingCommandLineRunner implements CommandLineRunner {

    @Override
    public void run(String... arg0) throws Exception {

        for (Booking b : bookingRepository.findAll()) {
            System.out.println(b.toString());
        }
    }

    @Autowired
    BookingRepository bookingRepository;

}

interface BookingRepository extends JpaRepository<Booking, Long> {

    Collection<Booking> findByBookingName(String bookingName);
}

@Entity
class Booking {

    @Id
    @GeneratedValue
    private Long id;
    private String bookingName;

    public Booking() {

    }

    public Booking(String bookingName) {
        super();
        this.bookingName = bookingName;
    }

    public Long getId() {
        return id;
    }

    public String getBookingName() {
        return bookingName;
    }

    public void setBookingName(String bookingName) {
        this.bookingName = bookingName;
    }

    @Override
    public String toString() {
        return "Booking [id=" + id + ", bookingName=" + bookingName + "]";
    }

}

错误

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v1.4.0.RC1)

2016-07-26 21:01:06.260  INFO 1984 --- [           main] c.example.BookingManagementApplication   : Starting BookingManagementApplication on Mahadev with PID 1984 (C:\Users\Naveen\Documents\workspace-sts-3.8.0.RELEASE\BookingManagement\target\classes started by Naveen in C:\Users\Naveen\Documents\workspace-sts-3.8.0.RELEASE\BookingManagement)
2016-07-26 21:01:06.270  INFO 1984 --- [           main] c.example.BookingManagementApplication   : No active profile set, falling back to default profiles: default
2016-07-26 21:01:06.460  INFO 1984 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5158b42f: startup date [Tue Jul 26 21:01:06 CDT 2016]; root of context hierarchy
2016-07-26 21:01:09.424  INFO 1984 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$5838840] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-07-26 21:01:10.100  INFO 1984 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-07-26 21:01:10.115  INFO 1984 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-07-26 21:01:10.117  INFO 1984 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.3
2016-07-26 21:01:10.273  INFO 1984 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-07-26 21:01:10.274  INFO 1984 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3822 ms
2016-07-26 21:01:10.573  INFO 1984 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2016-07-26 21:01:10.578  INFO 1984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-07-26 21:01:10.578  INFO 1984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-07-26 21:01:10.578  INFO 1984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-07-26 21:01:10.579  INFO 1984 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2016-07-26 21:01:11.100  INFO 1984 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-07-26 21:01:11.120  INFO 1984 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2016-07-26 21:01:11.219  INFO 1984 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.9.Final}
2016-07-26 21:01:11.220  INFO 1984 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2016-07-26 21:01:11.223  INFO 1984 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2016-07-26 21:01:11.277  INFO 1984 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2016-07-26 21:01:11.407  INFO 1984 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2016-07-26 21:01:12.099  INFO 1984 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2016-07-26 21:01:12.121  INFO 1984 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2016-07-26 21:01:12.211  INFO 1984 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2016-07-26 21:01:12.382  INFO 1984 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executing SQL script from URL [file:/C:/Users/Naveen/Documents/workspace-sts-3.8.0.RELEASE/BookingManagement/target/classes/data.sql]
2016-07-26 21:01:12.391  WARN 1984 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookingCommandLineRunner': Unsatisfied dependency expressed through field 'bookingRepository': Error creating bean with name 'bookingRepository': Cannot create inner bean '(inner bean)#126f8f24' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#126f8f24': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Naveen/Documents/workspace-sts-3.8.0.RELEASE/BookingManagement/target/classes/data.sql]: insert into booking(booking_name) values("Chris"); nested exception is org.h2.jdbc.JdbcSQLException: Column "Chris" not found; SQL statement:
insert into booking(booking_name) values("Chris") [42122-192]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookingRepository': Cannot create inner bean '(inner bean)#126f8f24' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#126f8f24': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Naveen/Documents/workspace-sts-3.8.0.RELEASE/BookingManagement/target/classes/data.sql]: insert into booking(booking_name) values("Chris"); nested exception is org.h2.jdbc.JdbcSQLException: Column "Chris" not found; SQL statement:
insert into booking(booking_name) values("Chris") [42122-192]
2016-07-26 21:01:12.391  INFO 1984 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2016-07-26 21:01:12.392  INFO 1984 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2016-07-26 21:01:12.402  INFO 1984 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
2016-07-26 21:01:12.413  INFO 1984 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2016-07-26 21:01:12.454  INFO 1984 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report enable debug logging (start with --debug)


2016-07-26 21:01:12.496 ERROR 1984 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookingCommandLineRunner': Unsatisfied dependency expressed through field 'bookingRepository': Error creating bean with name 'bookingRepository': Cannot create inner bean '(inner bean)#126f8f24' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#126f8f24': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Naveen/Documents/workspace-sts-3.8.0.RELEASE/BookingManagement/target/classes/data.sql]: insert into booking(booking_name) values("Chris"); nested exception is org.h2.jdbc.JdbcSQLException: Column "Chris" not found; SQL statement:
insert into booking(booking_name) values("Chris") [42122-192]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookingRepository': Cannot create inner bean '(inner bean)#126f8f24' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#126f8f24': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Naveen/Documents/workspace-sts-3.8.0.RELEASE/BookingManagement/target/classes/data.sql]: insert into booking(booking_name) values("Chris"); nested exception is org.h2.jdbc.JdbcSQLException: Column "Chris" not found; SQL statement:
insert into booking(booking_name) values("Chris") [42122-192]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RC1.jar:1.4.0.RC1]
    at com.example.BookingManagementApplication.main(BookingManagementApplication.java:20) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookingRepository': Cannot create inner bean '(inner bean)#126f8f24' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#126f8f24': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Naveen/Documents/workspace-sts-3.8.0.RELEASE/BookingManagement/target/classes/data.sql]: insert into booking(booking_name) values("Chris"); nested exception is org.h2.jdbc.JdbcSQLException: Column "Chris" not found; SQL statement:
insert into booking(booking_name) values("Chris") [42122-192]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:187) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1213) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1053) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1018) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    ... 19 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#126f8f24': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Naveen/Documents/workspace-sts-3.8.0.RELEASE/BookingManagement/target/classes/data.sql]: insert into booking(booking_name) values("Chris"); nested exception is org.h2.jdbc.JdbcSQLException: Column "Chris" not found; SQL statement:
insert into booking(booking_name) values("Chris") [42122-192]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:448) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    ... 33 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Naveen/Documents/workspace-sts-3.8.0.RELEASE/BookingManagement/target/classes/data.sql]: insert into booking(booking_name) values("Chris"); nested exception is org.h2.jdbc.JdbcSQLException: Column "Chris" not found; SQL statement:
insert into booking(booking_name) values("Chris") [42122-192]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:116) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1600) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    ... 41 common frames omitted
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Naveen/Documents/workspace-sts-3.8.0.RELEASE/BookingManagement/target/classes/data.sql]: insert into booking(booking_name) values("Chris"); nested exception is org.h2.jdbc.JdbcSQLException: Column "Chris" not found; SQL statement:
insert into booking(booking_name) values("Chris") [42122-192]
    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:494) ~[spring-jdbc-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:231) ~[spring-jdbc-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:48) ~[spring-jdbc-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.runScripts(DataSourceInitializer.java:169) ~[spring-boot-autoconfigure-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.runDataScripts(DataSourceInitializer.java:119) ~[spring-boot-autoconfigure-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.onApplicationEvent(DataSourceInitializer.java:110) ~[spring-boot-autoconfigure-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.onApplicationEvent(DataSourceInitializer.java:48) ~[spring-boot-autoconfigure-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:382) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:336) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.postProcessAfterInitialization(DataSourceInitializedPublisher.java:70) ~[spring-boot-autoconfigure-1.4.0.RC1.jar:1.4.0.RC1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1723) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:113) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    ... 45 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLException: Column "Chris" not found; SQL statement:
insert into booking(booking_name) values("Chris") [42122-192]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.message.DbException.get(DbException.java:179) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.message.DbException.get(DbException.java:155) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:147) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.command.dml.Insert.prepare(Insert.java:270) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.command.Parser.prepareCommand(Parser.java:259) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.engine.Session.prepareLocal(Session.java:560) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.engine.Session.prepareCommand(Session.java:501) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1202) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:170) ~[h2-1.4.192.jar:1.4.192]
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:158) ~[h2-1.4.192.jar:1.4.192]
    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:473) ~[spring-jdbc-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    ... 59 common frames omitted

1 个答案:

答案 0 :(得分:2)

我相信有一个导致问题的init SQL脚本(尽管问题中没有显示)

这个堆栈框架暗示:

    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java

该脚本可能包含以下SQL语句

insert into booking(booking_name) values("Chris")

应该是

insert into booking(booking_name) values('Chris')

(单引号而非双引号)

请注意,iirc,ANSI SQL标准使用单引号来引用字符串文字。某些DBMS支持字符串文字的双引号,但它不是标准的,在某些DBMS中它的含义不同(例如Oracle,双引号实际上使它成为一列。我想这同样适用于H2)