使用SQLite休眠数据库创建后无法第二次运行应用程序



我正在使用Spring引导、JPA、Hibernate和;IntelliJ中的带渐变构建系统的SQLite数据库。当没有SQLiteDB文件时,一切第一次都很好。它将创建该文件,并创建具有正确定义的所有表,我可以使用我的应用程序进行所有DB操作

但当我第二次运行它时,它没有运行,给了我一个我无法解决的错误。因为这是我第一次这样做

错误如下。

由:org.hubinate.exception.GenericJDBCException引起:错误访问处的表元数据org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47(在org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113(在org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99(
。。。另外35个

由:org.sqlite.SQLiteException引起:[sqlite_ERROR]SQL在处出现错误或缺少数据库(复合SELECT中的术语太多(org.sqlite.core.DB.newSQLException(DB.java:941(org.sqlite.core.DB.newSQLException(DB.java:953(org.sqlite.core.DB.thropex(DB.java:918(org.sqlite.core.NativeDB.prepare_utf8(Native Method(org.sqlite.core.NativeDB.reprepare(NativeDB.java:134(org.sqlite.core.DB.prepare(DB.java:257(…25更多



现在我对一无所知

org.hibernate.exception.GenericJDBCException:访问表时出错元数据

org.sqlite.SQLiteException:[sqlite_ERROR]SQL错误或丢失数据库(复合SELECT中的术语太多(


我的application.properties文件如下

##Database Properties
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.datasource.url=jdbc:sqlite:MYDATABASE.db
spring.datasource.username=root
spring.datasource.password=

#Hibernate Properties
#The SQL dialect makes hibernate generate better SQL for chosen database
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLiteDialect

#Hibernate DDL auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=update
spring.main.web-environment=false
spring.main.web-application-type=none
##Uncomment below 2 lines to enable hibernate JDBC queries/logs
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

有人经历过这种事吗?请帮忙。

我怀疑问题可能与以下行的设置有关:

spring.jpa.hibernate.ddl-auto=update

据我所知,hibernate会在启动时尝试更新现有的模式。为此,Hibernate需要解析现有表的结构,因此需要获取元数据。看看您得到的异常,我相信它无法使用SQLLite JDBC驱动程序获取元数据。这也可以解释为什么第一次运行应用程序时没有出现任何错误。在这种情况下,Hibernate从头开始创建模式,因此没有错误。

我建议您在开发阶段使用create-drop,在投入生产时使用none

您可以参考另一个问题的答案,该问题更详细地解释了设置:spring.jpa.hibernate.ddl-auto属性在spring中究竟是如何工作的?

最新更新