Load Spring-Boot Database with Test Data

匿名 (未验证) 提交于 2019-12-03 00:54:02

问题:

Goal: Leverage spring-boot Data Initialize features to create a simple database and load it with data.

Problem: Receiving an error during spring-boot start up.

org.hibernate.tool.hbm2ddl.SchemaExport  : Column "FIRSTNAME" not found; SQL statement

More of the spring-boot start-up output:

2015-03-06 17:32:30.919  INFO 3688 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executing SQL script from URL [file:/E:/spring-workspace/TestApp/target/classes/schema.sql] 2015-03-06 17:32:30.926  INFO 3688 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executed SQL script from URL [file:/E:/spring-workspace/TestApp/target/classes/schema.sql] in 4 ms. 2015-03-06 17:32:31.024  INFO 3688 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default' 2015-03-06 17:32:31.034  INFO 3688 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [     name: default     ...] 2015-03-06 17:32:31.114  INFO 3688 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.6.Final} 2015-03-06 17:32:31.119  INFO 3688 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found 2015-03-06 17:32:31.120  INFO 3688 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist 2015-03-06 17:32:31.373  INFO 3688 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final} 2015-03-06 17:32:31.427  INFO 3688 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect 2015-03-06 17:32:31.545  INFO 3688 --- [           main] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory 2015-03-06 17:32:31.848  INFO 3688 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export 2015-03-06 17:32:31.853 ERROR 3688 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000388: Unsuccessful: insert into customer (firstname, lastname) values ('James', 'Last') 2015-03-06 17:32:31.853 ERROR 3688 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Column "FIRSTNAME" not found; SQL statement: insert into customer (firstname, lastname) values ('James', 'Last') [42122-176] 2015-03-06 17:32:31.856  INFO 3688 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete

schema.sql found in /resources

drop table customer if exists;  create table customer (     id bigint auto_increment,     firstname varchar(80) null,     lastname varchar(80) null );

import.sql found in /resources

insert into customer (firstname, lastname) values ('James', 'Last');

pom.xml

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">     <modelVersion>4.0.0</modelVersion>     <parent>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-parent</artifactId>         <version>1.1.8.RELEASE</version>     </parent>     <artifactId>TestApp</artifactId>     <packaging>war</packaging>     <name>Spring Boot Web JSP Sample</name>     <description>Spring Boot Web JSP Sample</description>     <url>http://projects.spring.io/spring-boot/</url>     <organization>         <name>Pivotal Software, Inc.</name>         <url>http://www.spring.io</url>     </organization>     <properties>         <main.basedir>${basedir}/../..</main.basedir>         <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>     </properties>     <dependencies>         <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-web</artifactId>         </dependency>         <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-tomcat</artifactId>             <scope>provided</scope>         </dependency>         <dependency>             <groupId>org.apache.tomcat.embed</groupId>             <artifactId>tomcat-embed-jasper</artifactId>             <scope>provided</scope>         </dependency>         <dependency>             <groupId>javax.servlet</groupId>             <artifactId>jstl</artifactId>         </dependency>        <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-data-jpa</artifactId>         </dependency>         <dependency>             <groupId>com.h2database</groupId>             <artifactId>h2</artifactId>         </dependency>                    <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-test</artifactId>             <scope>test</scope>         </dependency>     </dependencies>     <build>         <plugins>             <plugin>                 <groupId>org.springframework.boot</groupId>                 <artifactId>spring-boot-maven-plugin</artifactId>             </plugin>             <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-surefire-plugin</artifactId>                 <configuration>                     <useSystemClassLoader>false</useSystemClassLoader>                 </configuration>             </plugin>         </plugins>     </build> </project>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!