jpa Sping Boot 引发错误:创建名为“dataSourceScriptDatabaseInitializer”的bean时出错

agxfikkp  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(99)

我正试图使用Sping Boot 运行简单的JPA应用程序。当我运行应用程序时,它一直抛出相同的错误。
我一直在犯这个错误:

Error:Error:无法执行文件[C:\Users\test.test.000\Downloads\JAP_leaning\target\classes\data.sql]的SQL脚本语句#1:插入人体(name,location,birth_date)值('Tom','USA',null)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. documentBean(AbstractAutowireCapableBeanFactory.java:599)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. BeanBean(AbstractAutowireCapableBeanFactory.java:521)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.beans.factory.support.AbstractBeanFactory.supporta$doGetBean$0(AbstractBeanFactory.java:325)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)~[spring-beans-6.1.2.jar:在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:312)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.context.support.AbstractApplicationContext. finishBeanFactoryList(AbstractApplicationContext.java:960)~[spring-context-6.1.2.jar:6.1.2] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625)~[spring-context-6.1.2.jar:6.1.2] at org.springframework. Boot .web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)~[spring-boot-3.2.1.jar:3.2.1] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)~[spring-boot-3.2.1.jar:在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:464)~[spring-boot-3.2.1.jar:3.2.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)~[spring-boot-3.2.1.jar:3.2.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)1358)~[spring-boot-3.2.1.jar:3.2.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1347)~[spring-boot-3.2.1.jar:3.2.1] at com.example.jpa_learning.boot_main_class.main(boot_main_class.java:16)~[classes/:na]原因:org.springframework.jdbc.jdbc.init.ScriptStatementFailedException:无法执行文件[C:\Users\Shubham Mishra.SHUBHAM.000\Downloads\JAP_leaning\JAP_leaning\target\classes\data.sql]的SQL脚本语句#1:在person(name,location,birth_date)中插入值('Tom','USA',null)at org.springframework.jdbc. jobs.init.ScriptUtils.executeSqlScript(ScriptUtils. java:282)~[spring-jdbc-6.1.2.jar:6.1.2] at org.springframework.jdbc. jobs.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:254)~[spring-jdbc-6.1.2.jar:6.1.2] at org.springframework.jdbc.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils. java:54)~[spring-jdbc-6.1.2.jar:6.1.2] at org.springframework. Boot .jdbc.init.DataSourceScriptDatabaseInitializer. running(DataSourceScriptDatabaseInitializer.java:87)~[spring- Boot -3.2.1.jar:3.2.1] at org.springframework. Boot .sql.init.AbstractScriptDatabaseInitializer. runtime(AbstractScriptDatabaseInitializer.java:146)~[spring- Boot -3.2.1.jar:3.2.1] at org.springframework. Boot .sql.init.AbstractScriptDatabaseInitializer. applyScript(AbstractScriptDatabaseInitializer.java:108)~[spring- Boot -3.2.1.jar:3.2.1] at org.springframework. Boot .sql.init.AbstractScriptDatabaseInitializer. applyDataBase(AbstractScriptDatabaseInitializer.java:102)~[spring- Boot -3.2.1.jar:3.2.1] at org.springframework. Boot .sql.init.AbstractScriptDatabaseInitializer.initializeDatabase(AbstractScriptDatabaseInitializer.java:77)~[spring- Boot -3.2.1.jar:3.2.1] at org.springframework. Boot .sql.init.AbstractScriptDatabaseInitializer. afterPropertySet(AbstractScriptDatabaseInitializer.java:66)~[spring- Boot -3.2.1.jar:3.2.1] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1820)~[spring-beans-6.1.2.jar:6.1.2] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1769)~[spring-beans-6.1.2.jar:6.1.2]. 18 common frames omitted For:org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException:列“ID”不允许为NULL; SQL语句:插入人体(name,location,birth_date)值[23502-224] at org.h2.message.DbException.getJdbcSQLExcException Exception.java:520)~[h2-2.2.224.jar:2.2.224] at org.h2.message.DbException.getJdbcSQLExException(DbException.java:489)~[h2-2.2.224.jar:2.2.224] at org.h2.message.DbException.get(DbException.java:223)~[h2-2.2.224.jar:2.2.224] at org.h2.message.DbException.get(DbException.java:199)~[h2-2.2.224.jar:2.2.224] at org.h2.table.Column.validateConvertUpdateSequence(Column.java:365)~[h2-2

ny6fqffe

ny6fqffe1#

如果你仔细阅读stacktrace,你会发现以下错误消息:
无法执行文件[C:\Users\test.test.000\Downloads\JAP_leaning\JAP_leaning\target\classes\data.sql]的SQL脚本语句#1:插入到人员(姓名、位置、出生日期)值(“Tom”、“USA”、null)

列“ID”不允许NULL; SQL语句:插入到person(name,location,birth_date)值('Tom','USA',null)
您还没有发布足够的细节来确定这一点。

ID BIGINT PRIMARY KEY

字符串
如果希望ID自动填充和递增,则需要将其更改为

ID BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY

相关问题