目标:利用spring-boot Data Initialize功能创建一个简单的数据库并使用数据加载它。
问题:在春季启动期间收到错误。
org.hibernate.tool.hbm2ddl.SchemaExport : Column "FIRSTNAME" not found; SQL statement
更多弹簧启动启动输出:
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
在/ resources 中找到schema.sql
drop table customer if exists;
create table customer (
id bigint auto_increment,
firstname varchar(80) null,
lastname varchar(80) null
);
在/ resources 中找到import.sql
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>