使用java的SQLite数据库访问

时间:2016-11-24 09:58:48

标签: java spring hibernate sqlite

我需要使用java访问SQLite数据库。我收到这个错误:

  

引起:org.hibernate.boot.registry.selector.spi.StrategySelectionException:无法将名称[org.hibernate.dialect.SQLiteDialect]解析为策略[org.hibernate.dialect.Dialect]

每当我想创建sessionFactory bean时。

数据库属性:

db.driver.class=org.sqlite.JDBC
db.server.url=jdbc:sqlite:"G:\\Ausbildung\\username\\Database\\informations.db"
db.username=
db.password=

db.hibernate.dialect=org.hibernate.dialect.SQLiteDialect
db.hibernate.schema=DATA
db.hibernate.hbm2ddl.auto=update

xml文件中的bean声明:

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
        lazy-init="true">
        <property name="driverClassName">
            <value>${db.driver.class}</value>
        </property>
        <property name="url">
            <value>${db.server.url}</value>
        </property>
        <property name="username">
            <value>${db.username}</value>
        </property>
        <property name="password">
            <value>${db.password}</value>
        </property>
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
        lazy-init="true">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan">
            <list>
                <value>com.mainfirst.bloomberg.invoice.report.model</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${db.hibernate.dialect}</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.default_schema">${db.hibernate.schema}</prop>
                <prop key="hibernate.hbm2ddl.auto">${db.hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.connection.CharSet">utf8</prop>
                <prop key="hibernate.connection.characterEncoding">utf8</prop>
                <prop key="hibernate.connection.useUnicode">true</prop>
            </props>
        </property>
    </bean>

我找不到我犯的错误。这个结构与Apache Derby一起使用。我只更改了hibernate.dialect和driver.class以及server.url。

如果我删除了db.server.url中的“”,我会收到错误

  

引起:java.lang.AbstractMethodError:org.sqlite.Conn.isValid(I)Z

提前致谢

1 个答案:

答案 0 :(得分:1)

修复了将此SQLite方言用于hibernate的问题:

<groupId>com.enigmabridge</groupId>
<artifactId>hibernate4-sqlite-dialect </artifactId>
<version>0.1.0</version>