Grails - 使用java域类来使用GORM创建grails域类 [英] Grails - use java domain classes to create grails domain classes using GORM

查看:106
本文介绍了Grails - 使用java域类来使用GORM创建grails域类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发现以下情况的部分答案,但需要进一步澄清。

有以下情况:


  • 以java编写的域类

  • 域类未通过hibernate映射到数据库

  • 由java服务器使用,它在将结果作为序列化的java类返回给客户端之前,只是执行密集型计算。


  • 创建一个可以执行以下操作的grails应用程序:


    1. 使用java域类作为grails域类

    2. 具有通过GORM映射到DB的java域类
    3. 能够从groovy域创建java域类类,以便能够将它发送到java服务器进行处理,然后接收java类的响应并将其转换为groovy类,以便使用GORM映射存储到数据库中
    4. 基本上具有hav ea grails应用程序处理用户交互并为处理java类的外部java服务器管理对象持久性

    从以下文章( 使用Java bean作为Grails域类)我看到java域通过简单地定义约束就可以在grails中使用类,但是如果类是使用hibernate映射的。解决方案:








      李>我正在考虑为java域模型写一个等价的groovy域模型。然而,这看起来像很多工作,对java类的修改将不得不在groovy类中复制。然后我需要编写函数来创建groovy中的java类类,以便将java类传递给java处理服务器,反之亦然。


    实现上述场景的所有建议都是受欢迎的。

    谢谢。

    解决方案

    但是从您指出的文档中,您可能会看到:


    1. 为您的Java对象创建hibernate xml映射

    2. 在您的Grails项目中使用您的Java对象(使用hibernate映射)
    3. 在UserBeanConstraints.groovy中添加Gorm约束


    Found some partial answers to the below scenario but require further clarification.

    Have the following situation:

    • domain classes written in java
    • the domain classes are not mapped to a DB through hibernate
    • the java classes are used by a java server which simply performs intensive computations before returning result to client as a serialized java class

    What I would like to do:

    create a grails application which could do the following:

    1. use the java domain classes as grails domain classes
    2. have the java domain classes mapped to DB by GORM
    3. be able to create the java domain class from the groovy domain class in order to be able to send it to the java server for processing and then receive the java class response and transform it to groovy class in order to store in DB with GORM mapping
    4. basically have a grails application handle the user interaction and manage the object persistence for the external java server that processes the java classes

    From the following post (Using Java beans as Grails domain classes) I see that the java domain classes can be used in grails by simply defining constraints, but this is if the classes are mapped with hibernate. In my case I want the classes to be mapped by GORM.

    Solution:

    • i was thinking about writing an equivalent groovy domain model for the java domain model. This however seems like a lot of work and modification to the java class will have to be replicated in the groovy classes.
    • then i would need to write function to create the java class from the groovy class in order to pass the java class to the java processing server, and vice versa.

    All suggestions to implement the above scenario are welcome.

    Thanks.

    解决方案

    I haven't tried this, but from the documentation that you pointed to, it looks like you could:

    1. Create hibernate xml mappings for your Java objects
    2. Use your Java objects (with hibernate mappings) in your Grails project
    3. Add Gorm constraints in UserBeanConstraints.groovy

    这篇关于Grails - 使用java域类来使用GORM创建grails域类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆