如何配置Grails3.1.1以使用Hibernate5

如何配置Grails3.1.1以使用Hibernate5,hibernate,grails,gorm,hibernate-5.x,grails-3.1,Hibernate,Grails,Gorm,Hibernate 5.x,Grails 3.1,如何使用Grails3.1.1用户Hibernate5 以下操作报告Hibernate版本4.3.11.Final: 在Grails3.1.1中 grails创建应用程序hello311 编辑BootStrap.groovy,如下所示 grails run应用程序 控制台显示: Hibernate版本为:4.3.11.Final class BootStrap { def init = { servletContext -> println "Hibernate v

如何使用Grails3.1.1用户Hibernate5

以下操作报告Hibernate版本4.3.11.Final: 在Grails3.1.1中

  • grails创建应用程序hello311
  • 编辑BootStrap.groovy,如下所示
  • grails run应用程序
  • 控制台显示: Hibernate版本为:4.3.11.Final

    class BootStrap {
        def init = { servletContext ->
            println "Hibernate version is: ${org.hibernate.Version.getVersionString()}"
        }
        def destroy = {}
    }
    
    我的build.gradle未经编辑。create app命令生成以下build.gradle文件:

        buildscript {
        ext {
            grailsVersion = project.grailsVersion
        }
        repositories {
            mavenLocal()
            maven { url "https://repo.grails.org/grails/core" }
        }
        dependencies {
            classpath "org.grails:grails-gradle-plugin:$grailsVersion"
            classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
            classpath "org.grails.plugins:hibernate4:5.0.0"
        }
    }
    
    version "0.1"
    group "hello311"
    
    apply plugin:"eclipse"
    apply plugin:"idea"
    apply plugin:"war"
    apply plugin:"org.grails.grails-web"
    apply plugin:"org.grails.grails-gsp"
    apply plugin:"asset-pipeline"
    
    ext {
        grailsVersion = project.grailsVersion
        gradleWrapperVersion = project.gradleWrapperVersion
    }
    
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    
    dependencyManagement {
        imports {
            mavenBom "org.grails:grails-bom:$grailsVersion"
        }
        applyMavenExclusions false
    }
    
    dependencies {
        compile "org.springframework.boot:spring-boot-starter-logging"
        compile "org.springframework.boot:spring-boot-autoconfigure"
        compile "org.grails:grails-core"
        compile "org.springframework.boot:spring-boot-starter-actuator"
        compile "org.springframework.boot:spring-boot-starter-tomcat"
        compile "org.grails:grails-dependencies"
        compile "org.grails:grails-web-boot"
        compile "org.grails.plugins:cache"
        compile "org.grails.plugins:scaffolding"
        compile "org.grails.plugins:hibernate4"
        compile "org.hibernate:hibernate-ehcache"
        console "org.grails:grails-console"
        profile "org.grails.profiles:web:3.1.1"
        runtime "org.grails.plugins:asset-pipeline"
        runtime "com.h2database:h2"
        testCompile "org.grails:grails-plugin-testing"
        testCompile "org.grails.plugins:geb"
        testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
        testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
    }
    
    task wrapper(type: Wrapper) {
        gradleVersion = gradleWrapperVersion
    }
    
    assets {
        minifyJs = true
        minifyCss = true
    }
    

    将hibernate4依赖项更改为hibernate5不起作用。

    在build.gradle中,在buildscript{dependencies{…部分的文件顶部更改hibernate4插件的类路径依赖项,如下所示:

    classpath "org.grails.plugins:hibernate5:5.0.1"
    
    类路径部分用于类似schemaExport的渐变脚本,该部分不支持自动版本控制

    将编译hibernate4插件依赖项更改为以下内容:

    compile "org.grails.plugins:hibernate5"
    
    添加以下hibernate核心依赖项:

    compile "org.hibernate:hibernate-core:5.0.7.Final"
    
    将hibernate ehcache依赖项更改为5.0.7.1最终版本

    compile "org.hibernate:hibernate-ehcache:5.0.7.Final"
    

    这是我的完整build.gradle文件,它适用于我的Hibernate 5

    buildscript {
        ext {
            grailsVersion = project.grailsVersion
        }
        repositories {
            mavenLocal()
            maven { url "https://repo.grails.org/grails/core" }
        }
        dependencies {
            classpath "org.grails:grails-gradle-plugin:$grailsVersion"
            classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
            classpath "org.grails.plugins:hibernate5:5.0.1"
            classpath "org.grails.plugins:views-gradle:1.0.1"
        }
    }
    
    version "0.1"
    group "myGroup"
    
    apply plugin: "spring-boot"
    apply plugin: "war"
    apply plugin: "asset-pipeline"
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: "org.grails.grails-web"
    apply plugin: "org.grails.grails-gsp"
    apply plugin: "org.grails.plugins.views-json"
    
    ext {
        grailsVersion = project.grailsVersion
        gradleWrapperVersion = project.gradleWrapperVersion
    }
    
    assets {
        minifyJs = true
        minifyCss = true
    }
    
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    
    dependencyManagement {
        imports {
            mavenBom "org.grails:grails-bom:$grailsVersion"
        }
        applyMavenExclusions false
    }
    
    dependencies {
        compile "org.springframework.boot:spring-boot-starter-logging"
        compile "org.springframework.boot:spring-boot-starter-actuator"
        compile "org.springframework.boot:spring-boot-autoconfigure"
        compile "org.springframework.boot:spring-boot-starter-tomcat"
        compile "org.grails:grails-dependencies"
        compile "org.grails:grails-web-boot"
        compile "org.grails.plugins:cache"
        compile "org.grails.plugins:scaffolding"
    
        compile "org.grails.plugins:views-json:1.0.1"
    
        compile "org.grails.plugins:hibernate5"
        compile "org.hibernate:hibernate-core:5.0.7.Final"
        compile "org.hibernate:hibernate-ehcache:5.0.7.Final"
    
        console "org.grails:grails-console"
        profile "org.grails.profiles:web:3.1.1"
        runtime "org.grails.plugins:asset-pipeline"
    
        runtime files('grails-app/lib/ojdbc7.jar', 'grails-app/lib/xdb6.jar')
        compile files('grails/src/java')
    
        testCompile "org.grails:grails-plugin-testing"
        testCompile "org.grails.plugins:geb"
    
        // Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
        testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0'
    
        console "org.grails:grails-console"
    }
    
    task wrapper(type: Wrapper) {
        gradleVersion = gradleWrapperVersion
    }
    

    我确实读过文档。他们说在Grails 3.0.x中使用Hibernate 5需要以下配置…他们还说如果使用Grails 3.1或更高版本,就不需要ResolutionsStrategy。我是不是遗漏了什么?我读文档是说在3.1中不需要特殊配置。不需要
    ResolutionsStrategy
    块,但您可以ed为
    hibernate core
    添加依赖项,并为现有
    hibernate ehcache
    依赖项指定正确的版本,因为如果没有这些依赖项,Grails/Gradle插件在未指定版本时解析版本将使用4.x版本,即使hibernate 5插件具有正确的dependenciesOK,同时删除两个dependenciesOKhibernate插件的备份和hibernate核心依赖项的添加工作正常。谢谢Burt。您仍然需要hibernate插件,否则您只能访问hibernate,而不能访问GORMOK,因此…删除类路径hibernate4依赖项,将编译hibernate4插件更改为hibernate5,将5.0.7.Final版本添加到hibernate ehcache、 并添加hibernate核心:5.0.7.Final。这似乎可行。它解决的hibernate5插件是版本5.0.1。这听起来正确吗?所以我们遇到了同样的问题。唯一的区别是我们使用版本5.0.8作为插件,使用版本5.1.0.Final作为其他hibernate依赖项。还有什么需要更改的吗ed?在本地运行良好,但部署到TCServer上时不行。我认为您希望所有Hibernate依赖项的版本都相同。但这可能不是您的问题。您使用的TC服务器是Java EE 6还是7容器?Hibernate 5是为EE 7设计的。我们无法将其部署到EE 6服务器上。经过多次尝试后,我们发现因为我们的EE 6服务器,lly回到了Grails 2和Hibernate 4。我们实际上使用的是Java 8JDK是Java SE版本-不是同一件事。问题是您使用的服务器实现了Java EE契约(API)的哪个版本?