【问题标题】:Grails Reverse Engineer DatabaseGrails 逆向工程师数据库
【发布时间】:2023-03-24 07:45:01
【问题描述】:

我正在尝试将 Grails 评估为即将到来的项目的解决方案。已经有一个大型数据库正在使用中,如果全部修改,则不会进行太多修改。我不想将数据库逆向工程为 GORM 域对象作为起点。

我在这里找到了一个http://www.grails.org/plugin/db-reverse-engineer。我安装并配置了它,但是当我运行它时,我一遍又一遍地看到相同的错误。堆栈跟踪如下。

有人可以帮我纠正错误,或者向 grails 推荐另一种逆向工程工具吗?我过去曾使用 Netbeans 将数据库逆向工程为运行良好的 JPA 实体。我希望与 Grails 有类似的东西。

| Error Error executing script DbReverseEngineer: javax/transaction/Transaction (NOTE: Stack trace has been filtered. Us
e --verbose to see entire trace.)
java.lang.NoClassDefFoundError: javax/transaction/Transaction
        at grails.plugin.reveng.GrailsJdbcBinder.readDatabaseSchema(GrailsJdbcBinder.groovy:51)
        at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:93)
        at org.hibernate.cfg.JDBCBinder$readFromDatabase.call(Unknown Source)
        at grails.plugin.reveng.GrailsJdbcMetaDataConfiguration.readFromJDBC(GrailsJdbcMetaDataConfiguration.groovy:32)
        at grails.plugin.reveng.GrailsJdbcMetaDataConfiguration$readFromJDBC.call(Unknown Source)
        at grails.plugin.reveng.Reenigne.buildConfiguration(Reenigne.groovy:114)
        at grails.plugin.reveng.Reenigne.execute(Reenigne.groovy:60)
        at grails.plugin.reveng.Reenigne$execute.call(Unknown Source)
        at grails.plugin.reveng.RevengRunner.run(RevengRunner.groovy:81)
        at grails.plugin.reveng.RevengRunner$run.call(Unknown Source)
        at DbReverseEngineer$_run_closure1.doCall(DbReverseEngineer:36)
        at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
        at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:1
85)
        at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
        at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
        at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
        at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
        at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
        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$0.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:591)
        at gant.Gant.executeTargets(Gant.groovy:590)
Caused by: java.lang.ClassNotFoundException: javax.transaction.Transaction
        ... 29 more
| Error Error executing script DbReverseEngineer: javax/transaction/Transaction

【问题讨论】:

  • 你使用的是什么版本的 Grails?

标签: grails grails-orm reverse-engineering


【解决方案1】:

实际上这个插件与 Hibernate 4... 不兼容。但由于上次推送是很久以前的事了,看起来你不会很快得到一个新版本来使用它:)

但是,您仍然可以继续使用此版本的 Grails 和 db-reverse-engineer:0.5 插件,只需将您的 Hibernate 版本切换回 3。而且这样做非常容易!

在 BuildConfig.groovy 中,注释该行 运行时 ":hibernate4:4.X.X.X"

然后添加: 运行时“:休眠:3.6.10.17”

(顺便说一句,不要忘记将正确的连接器添加到您的数据库中,我自己使用这个依赖项: 编译'mysql:mysql-connector-java:5.1.22' )

【讨论】:

  • 我正在使用 Hibernate 4,我将尝试将其切换为 Hibernate 3,看看会发生什么。一旦它被逆向工程,我可以毫无问题地将它切换回 Hibernate 4 吗?
  • 应该没问题...问题出在Hibernate API,从H3改成H4。这就是逆向工程插件不再起作用的原因。但是,您可能需要稍微调整一下。永远不要忘记这次报复。插件从未完成。它确实很有用,但应该作为您需要适应的基础。不过,我目前正在努力:)
  • 太棒了!感谢您的回复!
【解决方案2】:

嗯,插件使用Hibernate Tools 进行逆向工程,所以你可以尝试直接使用它们。

【讨论】:

  • 在 Hibernate Code Generation Configuration 窗口中,我是否只需选择 Domain 作为 Exporter 的类型?然后,复制并粘贴到 grails-app/domain 中?
  • 对不起,我不知道。
  • 到目前为止,我创建了域类和休眠 xml 文件。域类重命名为 *.groovy 并放入 /src/main/groovy/com/app,休眠 xml 文件放入 /conf。到目前为止,我能够生成单独的 CRUD 接口。我希望通配符能在这方面发挥作用。
  • 为了进一步说明我过去的评论,您可以保留带有 EJB 注释的 .java 类,无需重命名它们。
【解决方案3】:

有一个新版本修复了许多这样的错误:它是0.5.1 insead of 0.5

BuildConfig.groovy

runtime ':db-reverse-engineer:0.5.1'

【讨论】:

  • 我在使用 0.5.1 版本时收到了同样的错误。按照@Loic Cara 的建议切换到 Hibernate 3 对我有用。
【解决方案4】:

我也遇到了同样的问题,但我没有切换到休眠 3.x 版本主要问题是连接器,取消注释 BuildConfig.groovy 中的 mysql 连接器 我已经在 grails 应用程序的 lib 文件夹中添加了 javax.transaction jar,这解决了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 2011-12-21
    • 2012-06-24
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    相关资源
    最近更新 更多