java - Hibernate with SQLite 无法在数据库创建后第二次运行应用程序

标签 java hibernate sqlite spring-boot jpa

我正在使用 Spring boot、JPA、Hibernate 和 SQLite 数据库以及 IntelliJ 中的 Gradle Build 系统来开发 JavaFX 应用程序。当没有 SQLite DB 文件时,第一次一切都运行良好。它将创建该文件并创建具有正确定义的所有表,我可以使用我的应用程序执行所有数据库操作。

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

错误如下。

Caused by: org.hibernate.exception.GenericJDBCException: Error accessing tables metadata at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
... 35 more

Caused by: org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (too many terms in compound SELECT) at org.sqlite.core.DB.newSQLException(DB.java:941) at org.sqlite.core.DB.newSQLException(DB.java:953) at org.sqlite.core.DB.throwex(DB.java:918) at org.sqlite.core.NativeDB.prepare_utf8(Native Method) at org.sqlite.core.NativeDB.prepare(NativeDB.java:134) at org.sqlite.core.DB.prepare(DB.java:257) ... 25 more



现在我不知道

org.hibernate.exception.GenericJDBCException: Error accessing tables metadata

org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (too many terms in compound 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

您可以引用另一个问题的答案,其中更详细地解释了设置: How does spring.jpa.hibernate.ddl-auto property exactly work in Spring?

关于java - Hibernate with SQLite 无法在数据库创建后第二次运行应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58570755/

相关文章:

java - Firebase Java Lang 内存不足错误 : GC overhead limit exceeded

java - Hibernate : org. hibernate.PropertyAccessException:IllegalArgumentException

java - 我已经添加了所需的依赖项,但仍然遇到错误

java - 如何使用 Hibernate 和 Java 进行搜索

python-3.x - sqlite3表导入QTableWidget、sqlite3、PyQt5

java - 如何使用 SpringExtension 让我的测试与 JUnit5 一起工作?

java - JDK 的这段摘录是如何编译的?

java - 如何使用 hibernate/jpa 注释将一个类映射到不同的表

sqlite - 有什么办法可以让 SQLite 输出彩色吗?

sql - SOLite :Date formatter in SQLite