Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 在Grails中使用Firebird数据库的步骤_Hibernate_Grails_Jdbc_Firebird_Jaybird - Fatal编程技术网

Hibernate 在Grails中使用Firebird数据库的步骤

Hibernate 在Grails中使用Firebird数据库的步骤,hibernate,grails,jdbc,firebird,jaybird,Hibernate,Grails,Jdbc,Firebird,Jaybird,我正在尝试将我的Grails应用程序连接到Firebird数据库 我正在使用: Grails2.2.1 JDK1.7 火鸟2.5.2 杰比德2.2.2 到目前为止,我所做的就是: 我从以下站点下载了Jaybird-2.2.2JDK_1.7.zip 我解压缩了这个文件,并将jaybird-2.2.2.jar复制到我的应用程序的lib文件夹中 在BuildConfig.groovy中,我向依赖项部分添加了运行时“org.firebirdsql.jdbc:jaybird:2.2” 我编辑了Dat

我正在尝试将我的Grails应用程序连接到Firebird数据库

我正在使用:

  • Grails2.2.1
  • JDK1.7
  • 火鸟2.5.2
  • 杰比德2.2.2
到目前为止,我所做的就是:

  • 我从以下站点下载了Jaybird-2.2.2JDK_1.7.zip
  • 我解压缩了这个文件,并将jaybird-2.2.2.jar复制到我的应用程序的lib文件夹中
  • 在BuildConfig.groovy中,我向依赖项部分添加了运行时“org.firebirdsql.jdbc:jaybird:2.2”
  • 我编辑了DataSource.groovy,详情如下
数据源部分:

dataSource {
    pooled = false
    driverClassName = "org.firebirdsql.jdbc.FBDriver"
    dialect = "org.hibernate.dialect.FirebirdDialect"
    username = "SYSDBA"
    password = "masterkey"
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.provider_class = 'org.firebirdsql.pool.FBSimpleDataSource'
}
休眠部分:

dataSource {
    pooled = false
    driverClassName = "org.firebirdsql.jdbc.FBDriver"
    dialect = "org.hibernate.dialect.FirebirdDialect"
    username = "SYSDBA"
    password = "masterkey"
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.provider_class = 'org.firebirdsql.pool.FBSimpleDataSource'
}

(我在上述章节中也有
cache.region.factory\u class='net.sf.ehcache.hibernate.EhCacheRegionFactory
cache.provider\u class='com.opensymphony.oscache.hibernate.OSCacheProvider'
,但两者都没有区别。)

运行我的Grails应用程序时,启动失败,出现一个巨大错误,归结为以下消息:

java.lang.IllegalStateException: Could not load JDBC driver class [org.firebirdsql.jdbc.FBDriver]
我已经在网络上进行了广泛的搜索,但是我在任何地方都找不到一个可以工作的Grails/Firebird配置示例。有一个修复程序涉及复制minij2ee.jar,但这是针对不同的错误消息。另外,有人建议清空.grails文件夹——我已经尝试过了,但没有效果

有人能告诉我,如何让Grails与Firebird合作


以下是整个例外,尽管在启动过程中似乎会重复几次:

->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   662 | run . .  in java.lang.Thread

Caused by BeanCreationException: Error creating bean with name 'sessionFactory':
 Cannot resolve reference to bean 'dataSource' while setting bean property 'data
Source'; nested exception is org.springframework.beans.factory.BeanCreationExcep
tion: Error creating bean with name 'dataSource': Cannot resolve reference to be
an 'dataSourceUnproxied' while setting constructor argument; nested exception is
 org.springframework.beans.factory.BeanCreationException: Error creating bean wi
th name 'dataSourceUnproxied': Error setting property values; nested exception i
s org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessE
xceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'driverClassName' threw exception; nested exception is java.lang.Illega
lStateException: Could not load JDBC driver class [org.firebirdsql.jdbc.FBDriver
]
正在使用--verbose运行--stacktrace:

| Error Error running script --stacktrace --verbose: Cannot invoke method findAl
l() on null object
java.lang.NullPointerException: Cannot invoke method findAll() on null object
        at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:7
7)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaC
lassSite.java:45)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSi
teArray.java:45)
        at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.j
ava:32)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSi
teArray.java:45)
        at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMeta
MethodSite.java:55)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:116)
        at org.codehaus.groovy.grails.cli.ScriptNameResolver.resolvesTo(ScriptNa
meResolver.groovy:30)
        at org.codehaus.groovy.grails.cli.GrailsScriptRunner.getPotentialScripts
(GrailsScriptRunner.java:489)
        at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeScriptWithCa
ching(GrailsScriptRunner.java:429)
        at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeScriptWithCa
ching(GrailsScriptRunner.java:416)
        at org.codehaus.groovy.grails.cli.GrailsScriptRunner$executeScriptWithCa
ching.call(Unknown Source)
        at org.codehaus.groovy.grails.cli.interactive.InteractiveMode.parseAndEx
ecute(InteractiveMode.groovy:280)
        at org.codehaus.groovy.grails.cli.interactive.InteractiveMode$parseAndEx
ecute.callCurrent(Unknown Source)
        at org.codehaus.groovy.grails.cli.interactive.InteractiveMode.run(Intera
ctiveMode.groovy:133)
        at org.codehaus.groovy.grails.cli.interactive.InteractiveMode$run.call(U
nknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSi
teArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:112)
        at RunApp$_run_closure7_closure11.doCall(RunApp:127)
        at RunApp$_run_closure7_closure11.doCall(RunApp)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(Refl
ectiveInterceptor.java:1243)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1082)
        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1106)

        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:906)
        at groovy.lang.Closure.call(Closure.java:412)
        at groovy.lang.Closure.call(Closure.java:406)
        at groovy.lang.Closure.run(Closure.java:490)
        at java.lang.Thread.run(Thread.java:662)
| Error Error running script --stacktrace --verbose: Cannot invoke method findAl
l() on null object

下面是我的
BuildConfig.groovy
文件中的存储库块:

repositories {
    inherits true // Whether to inherit repository definitions from plugins

    grailsPlugins()
    grailsHome()
    grailsCentral()

    mavenLocal()
    mavenCentral()

    // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
    mavenRepo "http://snapshots.repository.codehaus.org"
    mavenRepo "http://repository.codehaus.org"
    mavenRepo "http://download.java.net/maven/2/"
    mavenRepo "http://repository.jboss.com/maven2/"
}

您可能缺少Jaybird所需的依赖项。您需要在类路径上包含
connector-api-1.5.jar
(在Jaybird发行版的
lib
文件夹中)。另一种选择是使用
jaybird-full-2.2.2.jar
(包括
connector-api-1.5.jar
)类

编辑

出于好奇,我安装了grails并试一试。我最初也得到了一个类似的错误(使用
grails控制台
),stacktrace向我显示了
java.lang.NoClassDefFoundError:javax/resource/ResourceException
。与文档相反,grails似乎没有检索可传递的依赖项(这是一个问题,请参见编辑2)

在我显式地在
'javax.resource:connector api:1.5'
上添加了运行时依赖项之后,例如:

dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.

    // runtime 'mysql:mysql-connector-java:5.1.22'
    runtime 'org.firebirdsql.jdbc:jaybird-jdk17:2.2.2',
            'javax.resource:connector-api:1.5'
}
有了这个额外的依赖,它就工作了。由于
连接器api
通常由应用程序服务器提供,因此最好将此api指定为
提供的
(您可能需要检查实际的部署环境)

如果您需要检索生成的密钥的支持(或者Gorm可能需要),那么我建议您也添加
'org.antlr:antlr runtime:3.4'
(作为
运行时
依赖项)

编辑2


在一些额外的测试之后,看起来像是首先将下载的jaybird库安装到
lib
,然后声明依赖项将使ivy在该本地库上创建依赖项,而不是从maven检索它。从lib文件夹中删除jaybird库后,从我的Ivy缓存中删除org.firebirdsql.jdbc文件夹后,它从Maven正确下载了它,包括
connector-api
依赖项。

我刚刚尝试将
connector-api-1.5.jar
jaybird-2.2.jar
一起放在lib文件夹中,但这似乎没有任何区别。我还尝试使用
jaybird-full-2.2.2.jar
代替普通的,但仍然没有成功。我将用完整的错误更新我的问题…我更改了我的依赖项以匹配您的,并从我的常春藤缓存中删除了jaybird的内容。我遇到了一系列错误,比如
服务器访问错误:连接重置url=http://grails.org/plugins/grails-jaybird-jdk17/tags/RELEASE_2_2_2/grails-jaybird-jdk17-2.2.2.jar
,所以我手动将
connector-api-1.5.jar
jaybird-jdk17-2.2.2.jar
复制到lib文件夹中。清理后,我仍然得到原始FBDriver错误。您的项目是否配置为也从Maven Central检索依赖项?是。如果我清除ivy缓存目录并运行,我会得到一些
服务器访问错误
,但最后它说
错误无法解析依赖项
,只列出了
org.firebirdsql.jdbc:jaybird-jdk17:2.2.2
javax.resource:connector api:1.5
。我必须将.jar文件复制到lib中才能通过这一步骤。出于某种原因,
java-version
说我正在运行JDK1.7,但我的
java\u HOME
一直都指向1.6–我一直在用错误的.jar代替Jaybird。我仍然和Maven有问题,但那是另外一个问题。您在为我的项目获得正确配置方面的指导是至关重要的。拜伊·丹基
cache.provider\u class='org.firebirdsql.pool.FBSimpleDataSource'
也可能是错误的,
FBSimpleDataSource
不是缓存提供程序。谢谢。你知道提供者类应该是什么吗?我在网上看到的另一个值是
com.opensymphony.oscache.hibernate.OSCacheProvider
,但我真的不知道这是否有效。要重新缓存provider,请查看hibernate文档;我相信如果你不指定它,它会使用默认值。很抱歉FBDrive输入错误,这是因为我从Windows控制台复制时出错了(现在在我的问题正文中修复了它)。驱动程序字符串绝对正确。至于stacktrace,恐怕我只有这些了。。。我不知道如何判断Jaybird是否在类路径上,但我确实在
常春藤缓存中看到了它,这表明它已被检测到。我对grails了解不够,无法帮助您