jeudi 16 avril 2015

Which steps enable SQLite with Spring-Boot and JPA?

To run SQLite with a Spring-boot (Version 1.2.3.RELEASE) application, I did these three steps:




  1. use the SQLiteDialect class from Spring boot and SQLite




  2. provide a JDBC driver; we used org.xerial:sqlite-jdbc (http://ift.tt/1xR8htX)




  3. configure the datasource; here with a spring-boot .yml file:



    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



Now, that's not enough. It ends with a "No enum constant org.springframework.orm.jpa.vendor.Database.SQLITE" error:



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]


Indeed the org.springframework.orm.jpa.vendor.Database class has no SQLITE value, sadly. However, the spring doc (http://ift.tt/1Ihm3H7) states:



If a given PersistenceProvider supports a database not listed here, the strategy class can still be specified using the fully-qualified class name.



That looks like I have to:




  1. remove the pointless


    jpa: database: SQLITE




configuration piece above, and



  1. Provide some "strategy class" instead.


Am I on the right path here ?


What do they mean with "strategy class" and how to get or implement it ?


Aucun commentaire:

Enregistrer un commentaire