4

试图让 SQLite 与 grails 一起工作......我在网上找到的东西似乎有点过时 - 对常春藤和插件等的引用,但基于这些:

http://stackoverflow.com/questions/1199512/grails-sqlite
http://bigohno.blogspot.com/2010/01/groovy-on-grails-sqlite.html
http://maven-repository.com/artifact/org.xerial/sqlite-jdbc/3.6.17

我已经能够让它在测试环境中工作......奇怪的是,当我“刺激战争”我的 grails 应用程序并部署到 tomcat 时它失败了:

找不到方言类:hibernate.SQLiteDialect

这是我的设置:

在 conf/hibernate 中为 SQLiteDialect 添加了一个类。这个 .java 取自这里http://code.google.com/p/hibernate-sqlite/

然后在我的 DataSource.groovy 我有:

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            // SQLite
            // !!!see also BuildConfig for Dependancies!!!
            dbCreate="update"
            url='jdbc:sqlite:C:\\sqlite-shell-win32-x86-3080100\\rss_1.db'
            logSql="true"
            dialect="hibernate.SQLiteDialect"
            driverClassName="org.sqlite.JDBC"
            readOnly="true"

        }
    }

    production {
        dataSource {
            // SQLite
            dbCreate="update"
            url="jdbc:sqlite:/opt/sqlite/dbs/rss/1/rss_1.db"
            logSql="true"
            dialect="hibernate.SQLiteDialect"
            driverClassName="org.sqlite.JDBC"
            readOnly="true"
            showsql="false"

        }
    }
}

在 BuildConfig.groovy 我有:

dependencies {

        runtime 'org.xerial:sqlite-jdbc:3.6.17'

    }

我还 jar'd 了 .java 方言类并放入 lib - 一些帖子说这有帮助。我还将 sqlite-jdbc-3.7.15-M1.jar 放在 lib 中。

现在,当我在我的开发环境中运行应用程序时,它运行良好......但是当我部署到 tomcat 时,我得到了方言错误。

我需要对方言的 prod 环境做些什么特别的事情吗?

4

1 回答 1

11

以下是使用 Grails 设置 SQLite 的方法:

从http://www.sqlite.org/download.html下载 SQLite ,解压并保存到一个目录。您可能还想为您的数据库创建目录。

从https://bitbucket.org/xerial/sqlite-jdbc下载 SQLite JDBC jar并将 jar 放入您的 grails lib 目录中。

下载一个 SQLite 方言...google 搜索,因为有很多,但你可以参考https://github.com/gwenn/sqlite-dialecthttps://gist.github.com/virasak/54436

在 grails 中,在 src/java 中创建一个类并将您的方言代码放入。

我还把这个类 jar'd 放在 lib 中。

设置您的 grails 数据源,例如:

dataSource {
            // SQLite
            dbCreate="update"
            url="jdbc:sqlite:/opt/sqlite/dbs/rss/1/rss_1.db"
            logSql="true"
            dialect="SQLiteDialect"
            driverClassName="org.sqlite.JDBC" 
}

注意:根据您的 sqlite 方言类是否在包中,您可能需要将包名添加到上面的方言中(我的没有)。

在 BuildConfig.groovy 中,添加对 sqlite jdbc 的依赖,如下所示:

dependencies {

        runtime 'org.xerial:sqlite-jdbc:3.6.17'

    }

这对我有用!

于 2013-10-30T20:12:37.840 回答