小编shf*_*ful的帖子

哪些步骤可通过Spring-Boot和JPA启用SQLite?

为了使用Spring-boot(1.2.3.RELEASE版本)应用程序运行SQLite,我执行了以下三个步骤:

  1. 使用Spring Boot和SQLite中的SQLiteDialect类

  2. 提供JDBC驱动程序;我们使用了org.xerial:sqlite-jdbc(http://mvnrepository.com/artifact/org.xerial/sqlite-jdbc/3.8.7

  3. 配置数据源;这里是spring-boot .yml文件:

       spring:
      datasource:
        url: jdbc:sqlite:<full-path-to-file>.db
        username: ...
        password: ...
        driverClassName: org.sqlite.JDBC
        ...
      jpa:
        database: SQLITE
        dialect: that.custom.SQLiteDialect
        hibernate:
          ddl-auto: update
    
    Run Code Online (Sandbox Code Playgroud)

现在,这还不够。它以“没有枚举常量org.springframework.orm.jpa.vendor.Database.SQLITE”错误结尾:

Field error in object 'spring.jpa' on field 'database': rejected value [SQLITE]; codes [typeMismatch.spring.jpa.database,typeMismatch.database,typeMismatch.org.springframework.orm.jpa.vendor.Database,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.jpa.database,database]; arguments []; default message [database]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.orm.jpa.vendor.Database' for property 'database'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to …
Run Code Online (Sandbox Code Playgroud)

java sqlite jpa spring-data spring-boot

5
推荐指数
1
解决办法
1万
查看次数

如何避免 Flyway 迁移锁定 SQLite 数据库?

我们使用 SQLite (Flyway v3.2.1、SQLite 3.7.13 和 org.xerial:sqlite-jdbc:3.8.7 驱动程序)进行 Flyway迁移

并行数据库连接的最大数量似乎至关重要。但是由于不同的原因,任何连接池大小的迁移都会失败。

1. 使用大小为 2 或更大的连接池

存在与多个并行数据库连接相关的锁定问题。在空的 SQLite 数据库上进行一次迁移,结果是:

o.f.core.internal.command.DbMigrate.(:)()  Current version of schema "main": << Empty Schema >>
o.f.core.internal.command.DbMigrate.(:)()  Migrating schema "main" to version 1 - initial
o.f.c.i.u.jdbc.TransactionTemplate.(:)()  Unable to restore autocommit to original value for connection
java.sql.SQLException: database is locked
    at org.sqlite.core.DB.throwex(DB.java:859) ~[sqlite-jdbc-3.8.7.jar:na]
    at org.sqlite.core.DB.exec(DB.java:142) ~[sqlite-jdbc-3.8.7.jar:na]
    at org.sqlite.jdbc3.JDBC3Connection.setAutoCommit(JDBC3Connection.java:152) ~[sqlite-jdbc-3.8.7.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_71]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_71]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_71]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_71]
    at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126) ~[tomcat-jdbc-7.0.56.jar:na]
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109) …
Run Code Online (Sandbox Code Playgroud)

java sqlite flyway

3
推荐指数
1
解决办法
3664
查看次数

标签 统计

java ×2

sqlite ×2

flyway ×1

jpa ×1

spring-boot ×1

spring-data ×1