我在一个Spring独立项目中工作。我试图使用H2DB进行快速测试。我遇到了两个必须具有相同根源的问题:
我有H2依赖在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 https://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>2.2.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.dreamseeker</groupId>
<artifactId>CondoAdmin</artifactId>
<version>1.0.0</version>
<name>CondoAdmin</name>
<description>Standalone project for condo administration</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>net.rgielen</groupId>
<artifactId>javafx-weaver-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我也在application.properties中添加了这一行:Spring. h2.sole.启用=true
我怀疑这是因为这不是一个网络应用程序,但我在互联网上找不到任何批准我的hipotesys的信息。
其次,我在资源目录中添加了一个脚本来填充我的H2DB但是一个异常是跳转,这基本上是抱怨一个不存在的列:
由以下原因引起:org. h2.jdbc.JdbcSQLSyn计数器错误异常:列"LASTNAME"没有发现列"LASTNAME"未找到;SQL语句:INSERT INTO Person(id,name,lastname,dni,公寓ID)VALUES(1,'Edgar','Hernandez','26659514-k','701')[4222-200]
这是我的实体类的代码:
/**
*
*/
package com.dreamseeker.models.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* @author Edgar Hernández
*
*/
@Entity
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;
private String lastName;
private String dni;
private String apartmentID;
public Person(String name, String lastName, String dni, String apartmentID) {
this.name = name;
this.lastName = lastName;
this.dni = dni;
this.apartmentID = apartmentID;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getLastName() {
return lastName;
}
public String getDNI() {
return dni;
}
public String getApartmentID() {
return apartmentID;
}
@Override
public String toString() {
return String.format(
"Person[name=%d, last name='%s', dni='%s', apartmentID='%s']",
name, lastName, dni, apartmentID);
}
}
该脚本有以下语句:
插入人员(id, name,lastname,dni,公寓ID)值(1,'Edgar','Hernandez','26659514-k','701');
这里看不到错误,字段声明正确,查询中引用同名…
这是整个日志:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
[32m :: Spring Boot :: [39m [2m (v2.2.1.RELEASE)[0;39m
[2m2020-02-19 21:10:37.851[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Starting application on DESKTOP-I4H91H1 with PID 9236 (started by Edgar Hernández in C:\Users\Edgar Hernández\Documents\Programacion\GIT repos\CondoAdmin\Spring)
[2m2020-02-19 21:10:37.854[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m No active profile set, falling back to default profiles: default
[2m2020-02-19 21:10:38.155[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Bootstrapping Spring Data repositories in DEFAULT mode.
[2m2020-02-19 21:10:38.201[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36m.s.d.r.c.RepositoryConfigurationDelegate[0;39m [2m:[0;39m Finished Spring Data repository scanning in 39ms. Found 2 repository interfaces.
[2m2020-02-19 21:10:38.465[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Starting...
[2m2020-02-19 21:10:38.539[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Start completed.
[2m2020-02-19 21:10:38.576[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mo.hibernate.jpa.internal.util.LogHelper [0;39m [2m:[0;39m HHH000204: Processing PersistenceUnitInfo [name: default]
[2m2020-02-19 21:10:38.627[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36morg.hibernate.Version [0;39m [2m:[0;39m HHH000412: Hibernate Core {5.4.8.Final}
[2m2020-02-19 21:10:38.731[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mo.hibernate.annotations.common.Version [0;39m [2m:[0;39m HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
[2m2020-02-19 21:10:38.831[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36morg.hibernate.dialect.Dialect [0;39m [2m:[0;39m HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
[2m2020-02-19 21:10:39.232[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36morg.hibernate.tuple.PojoInstantiator [0;39m [2m:[0;39m HHH000182: No default (no-argument) constructor for class: com.dreamseeker.models.entity.Person (class must be instantiated by Interceptor)
[2m2020-02-19 21:10:39.315[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mo.h.e.t.j.p.i.JtaPlatformInitiator [0;39m [2m:[0;39m HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
[2m2020-02-19 21:10:39.320[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mj.LocalContainerEntityManagerFactoryBean[0;39m [2m:[0;39m Initialized JPA EntityManagerFactory for persistence unit 'default'
[2m2020-02-19 21:10:39.341[0;39m [33m WARN[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36ms.c.a.AnnotationConfigApplicationContext[0;39m [2m:[0;39m Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Edgar%20Hern%c3%a1ndez/Documents/Programacion/GIT%20repos/CondoAdmin/Spring/target/classes/data.sql]: INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Columna "LASTNAME" no encontrada
Column "LASTNAME" not found; SQL statement:
INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701') [42122-200]
[2m2020-02-19 21:10:39.342[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Shutdown initiated...
[2m2020-02-19 21:10:39.343[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mcom.zaxxer.hikari.HikariDataSource [0;39m [2m:[0;39m HikariPool-1 - Shutdown completed.
[2m2020-02-19 21:10:39.348[0;39m [32m INFO[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mConditionEvaluationReportLoggingListener[0;39m [2m:[0;39m
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2m2020-02-19 21:10:39.357[0;39m [31mERROR[0;39m [35m9236[0;39m [2m---[0;39m [2m[JavaFX-Launcher][0;39m [36mo.s.boot.SpringApplication [0;39m [2m:[0;39m Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Edgar%20Hern%c3%a1ndez/Documents/Programacion/GIT%20repos/CondoAdmin/Spring/target/classes/data.sql]: INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Columna "LASTNAME" no encontrada
Column "LASTNAME" not found; SQL statement:
INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701') [42122-200]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140) [spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at com.dreamseeker.JavaFxApplication.init(JavaFxApplication.java:28) [classes/:na]
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:841) [jfxrt.jar:na]
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182) [jfxrt.jar:na]
at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_231]
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Edgar%20Hern%c3%a1ndez/Documents/Programacion/GIT%20repos/CondoAdmin/Spring/target/classes/data.sql]: INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Columna "LASTNAME" no encontrada
Column "LASTNAME" not found; SQL statement:
INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701') [42122-200]
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:626) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:254) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:49) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.runScripts(DataSourceInitializer.java:202) ~[spring-boot-autoconfigure-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.initSchema(DataSourceInitializer.java:119) ~[spring-boot-autoconfigure-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.onApplicationEvent(DataSourceInitializerInvoker.java:91) ~[spring-boot-autoconfigure-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.onApplicationEvent(DataSourceInitializerInvoker.java:38) ~[spring-boot-autoconfigure-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.publishEventIfRequired(DataSourceInitializedPublisher.java:99) ~[spring-boot-autoconfigure-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.postProcessAfterInitialization(DataSourceInitializedPublisher.java:90) ~[spring-boot-autoconfigure-2.2.1.RELEASE.jar:2.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1807) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 16 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Columna "LASTNAME" no encontrada
Column "LASTNAME" not found; SQL statement:
INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701') [42122-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:453) ~[h2-1.4.200.jar:1.4.200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429) ~[h2-1.4.200.jar:1.4.200]
at org.h2.message.DbException.get(DbException.java:205) ~[h2-1.4.200.jar:1.4.200]
at org.h2.message.DbException.get(DbException.java:181) ~[h2-1.4.200.jar:1.4.200]
at org.h2.table.Table.getColumn(Table.java:703) ~[h2-1.4.200.jar:1.4.200]
at org.h2.command.Parser.parseColumn(Parser.java:1450) ~[h2-1.4.200.jar:1.4.200]
at org.h2.command.Parser.parseColumnList(Parser.java:1435) ~[h2-1.4.200.jar:1.4.200]
at org.h2.command.Parser.parseInsertGivenTable(Parser.java:1804) ~[h2-1.4.200.jar:1.4.200]
at org.h2.command.Parser.parseInsert(Parser.java:1749) ~[h2-1.4.200.jar:1.4.200]
at org.h2.command.Parser.parsePrepared(Parser.java:954) ~[h2-1.4.200.jar:1.4.200]
at org.h2.command.Parser.parse(Parser.java:843) ~[h2-1.4.200.jar:1.4.200]
at org.h2.command.Parser.parse(Parser.java:815) ~[h2-1.4.200.jar:1.4.200]
at org.h2.command.Parser.prepareCommand(Parser.java:738) ~[h2-1.4.200.jar:1.4.200]
at org.h2.engine.Session.prepareLocal(Session.java:657) ~[h2-1.4.200.jar:1.4.200]
at org.h2.engine.Session.prepareCommand(Session.java:595) ~[h2-1.4.200.jar:1.4.200]
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235) ~[h2-1.4.200.jar:1.4.200]
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:212) ~[h2-1.4.200.jar:1.4.200]
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201) ~[h2-1.4.200.jar:1.4.200]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.4.1.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.4.1.jar:na]
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:605) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 32 common frames omitted
Exception in Application init method
Exception in thread "main" java.lang.RuntimeException: Exception in Application init method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:912)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Edgar%20Hern%c3%a1ndez/Documents/Programacion/GIT%20repos/CondoAdmin/Spring/target/classes/data.sql]: INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Columna "LASTNAME" no encontrada
Column "LASTNAME" not found; SQL statement:
INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701') [42122-200]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)
at com.dreamseeker.JavaFxApplication.init(JavaFxApplication.java:28)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:841)
... 2 more
Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Edgar%20Hern%c3%a1ndez/Documents/Programacion/GIT%20repos/CondoAdmin/Spring/target/classes/data.sql]: INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Columna "LASTNAME" no encontrada
Column "LASTNAME" not found; SQL statement:
INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701') [42122-200]
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:626)
at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:254)
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:49)
at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.runScripts(DataSourceInitializer.java:202)
at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.initSchema(DataSourceInitializer.java:119)
at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.onApplicationEvent(DataSourceInitializerInvoker.java:91)
at org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker.onApplicationEvent(DataSourceInitializerInvoker.java:38)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360)
at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.publishEventIfRequired(DataSourceInitializedPublisher.java:99)
at org.springframework.boot.autoconfigure.orm.jpa.DataSourceInitializedPublisher.postProcessAfterInitialization(DataSourceInitializedPublisher.java:90)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1807)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
... 16 more
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Columna "LASTNAME" no encontrada
Column "LASTNAME" not found; SQL statement:
INSERT INTO Person (id, name, lastname, dni, apartmentID) VALUES (1, 'Edgar', 'Hernandez', '26659514-k', '701') [42122-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.get(DbException.java:181)
at org.h2.table.Table.getColumn(Table.java:703)
at org.h2.command.Parser.parseColumn(Parser.java:1450)
at org.h2.command.Parser.parseColumnList(Parser.java:1435)
at org.h2.command.Parser.parseInsertGivenTable(Parser.java:1804)
at org.h2.command.Parser.parseInsert(Parser.java:1749)
at org.h2.command.Parser.parsePrepared(Parser.java:954)
at org.h2.command.Parser.parse(Parser.java:843)
at org.h2.command.Parser.parse(Parser.java:815)
at org.h2.command.Parser.prepareCommand(Parser.java:738)
at org.h2.engine.Session.prepareLocal(Session.java:657)
at org.h2.engine.Session.prepareCommand(Session.java:595)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:212)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201)
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:605)
... 32 more
总之,H2控制台仅适用于Web项目?我是否缺少配置?
解决:在评论中,有人给了我一个指向Spring Docs的链接,我在其中找到了这条信息:
所以这些是使用H2控制台的先决条件。就我而言,这不是一个基于网络的应用程序,所以不可能何塞。
未找到列LASTNAME
将lastName
更改为lastname
,然后重试。
我认为它会在数据库模式中创建为LAST_NAME
。
编辑:或者您可以在lastname字段声明之前添加@Col列(name="lastname")标记,以确保这将是列将获得的名称。