Search code examples
javaweb-serviceshibernatedropwizarddialect

SQLight dialect in Dropwizard for Hibernate


I'm Creating a project for tailor system as a RESTful web service using dropwizard and SQLight as database with hibernate.The problem is that hibernate have no dialect for SQLight so by searching got a class code for SQLightDialect.

now I have to add SQLightDialect class for hibernate to use and don't know how to do it in dropwizard.

Please help.


Solution

  • Solved by adding

    Map<String,String> s=new HashMap<String, String>();
        s.put("hibernate.dialect","Hibernate.SQLightDialect.SQLiteDialect");
        dbconfigurations.setProperties(s);
    

    in

    public class databaseConfiguration extends Configuration {
    
    @Valid
    @NotNull
    @JsonProperty
    DatabaseConfiguration dbconfigurations = new DatabaseConfiguration();
    
    public DatabaseConfiguration getDatabaseConfiguration() {
        //return dbconfigurations;
        Map<String,String> s=new HashMap<String,String>();
        s.put("hibernate.dialect","Hibernate.SQLightDialect.SQLiteDialect");
        dbconfigurations.setProperties(s);
        return dbconfigurations;
    }
    }
    

    Another Solution read on the Web is adding it in yml file like:

    database:
    # the name of your JDBC driver
    driverClass: org.postgresql.Driver
    # the username
    user: username
    # the password
    password: password
    # the JDBC URL
    url: jdbc:postgresql://localhost:5432/gis_database
    properties:
    hibernate.dialect: org.hibernate.spatial.dialect.postgis.PostgisDialect