要使用Spring-boot(版本1.2.3.RELEASE)应用程序运行SQLite,我执行了以下三个步骤:
>使用Spring boot and SQLite中的SQLiteDialect类
>提供JDBC驱动程序;我们用了
org.xerial:sqlite-jdbc(http://mvnrepository.com/artifact/org.xerial/sqlite-jdbc/3.8.7)
>配置数据源;这里有一个spring-boot .yml文件:
spring:
datasource:
url: jdbc:sqlite:.db
username: ...
password: ...
driverClassName: org.sqlite.JDBC
...
jpa:
database: SQLITE
dialect: that.custom.SQLiteDialect
hibernate:
ddl-auto: update
现在,这还不够.它以“No enum constant 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 type org.springframework.orm.jpa.vendor.Database for value 'SQLITE'; nested exception is java.lang.IllegalArgumentException: No enum constant org.springframework.orm.jpa.vendor.Database.SQLITE]
If a given PersistenceProvider supports a database not listed here, the strategy class can still be specified using the fully-qualified class name.
看起来我必须:
>删除毫无意义
JPA:
数据库:SQLITE
配置件上面,和
>改为提供一些“策略类”.
我在正确的道路上吗?
他们对“战略类”有什么意义以及如何获得或实施它?
UPDATE
解决方案:根据M. Deinum的评论,正确的配置如下:
spring:
datasource:
url: jdbc:sqlite:.db
username: ...
password: ...
driverClassName: org.sqlite.JDBC
...
jpa:
database-platform: that.custom.SQLiteDialect
hibernate:
ddl-auto: update
似乎没有“战略类”需要实施.
我现在已经得到了:删除的jpa:database:SQLITE行(对应于org.springframework.orm.jpa.vendor.Database类)根本不是必需的.这是一种方便的方式 – 对于大多数数据库而不是SQLite.
备注:当使用Hibernate时,那个database-platform = …条目就像Hibernate特定配置中的hibernate.dialect = that.custom.SQLiteDialect,它会产生同样的效果.