【问题标题】:Grails 1.0.3 Upgrade ProblemsGrails 1.0.3 升级问题
【发布时间】:2011-05-29 19:51:03
【问题描述】:

我正在尝试将 Grails 1.0.3 项目升级到 1.3.7,并且遇到了我认为相关的问题。

旧项目在conf/hibernate/Domain1.hbm.xml中有Hibernate xml文件我猜GORM在1.0.3中不存在?

我是否需要将 xml 文件中的内容本质上转换为域中域类中的 Groovy 代码/

任何其他细节都有帮助。谢谢。

更新 -

所有这些更改都是org.hibernate.DuplicateMappingException 的结果,看起来我可以移动域文件:Relevant Post 这真的是我想要做的吗?我的理解是,使用 GORM 我根本不需要使用 xml 文件。

这里有一个例外

2011-05-29 16:43:49,616 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is 

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping sportsdb.Event
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping sportsdb.Event
        at org.grails.tomcat.InlineExplodedTomcatServer.doStart(InlineExplodedTomcatServer.groovy:112)
        at org.grails.tomcat.InlineExplodedTomcatServer$doStart.callCurrent(Unknown Source)
        at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:97)
        at grails.web.container.EmbeddableServer$start.call(Unknown Source)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
        at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
        at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
        at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
        at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
        at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
        at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
        at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
        at RunApp$_run_closure1.doCall(RunApp:33)
        at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:427)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:415)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.executeTargets(Gant.groovy:590)
        at gant.Gant.executeTargets(Gant.groovy:589)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping sportsdb.Event
        ... 25 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate class/entity mapping sportsdb.Event
        ... 25 more
    Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping sportsdb.Event
        ... 25 more

【问题讨论】:

    标签: grails groovy grails-orm


    【解决方案1】:

    GORM 确实存在于 Grails 1.0.3 中。

    您可能只需要更新 1.3.7 的休眠配置。看看Grails and Hibernate - Reference Documentation

    除非您要映射到旧的或其他不寻常的数据库模式,否则标准 GORM 域建模是可行的方法。它非常灵活。

    【讨论】:

    • @JamesA - 感谢您的链接和信息。但是,与链接相比,休眠 xml 看起来不错,所以我不确定。还有其他想法吗?
    • @JamesA - 我相信我需要拥有休眠 xml 和具有扩展它们的功能的域对象。似乎它只是不喜欢我两者都有。
    • 是的,你需要 conf/hibernate 中的映射文件和 src/java 中的域类。
    • @JamesA - 我不会失去在域类上调用生成的方法的能力吗?
    • 您的域目录中是否定义了 sportsdb.Event 类?如果你使用的是休眠映射,它应该在 src/groovy 中。您仍然可以在域对象上调用 GORM 动态方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    相关资源
    最近更新 更多