简体   繁体   English

在grails应用程序和non grails应用程序之间共享域对象

[英]Sharing domain objects between a grails application and a non grails application

I have a grails application with some domain objects which get serialized as JSON. 我有一个grails应用程序,其中包含一些域对象,这些对象被序列化为JSON。 In another java/groovy project, I would like to use these domain objects. 在另一个java / groovy项目中,我想使用这些域对象。 If I publish a plugin, it looks like only other grails applications can use the plugin. 如果我发布插件,则看起来只有其他grails应用程序可以使用该插件。

I tried to create a raw groovy project with the domain classes and their data, and in my grails app, I have stubs like this: 我试图用域类和它们的数据创建一个原始的常规项目,在我的grails应用中,我有这样的存根:

class Fact extends com.domain.Fact {}

When I go to run my app, however, I get these 但是,当我运行我的应用程序时,我得到了这些

Caused by MappingException: Missing type or column for column[facts_fact] on domain[DeclarationDefinition] referencing[com.domain.Fact]
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync

Is what I'm doing possible, or is there a better way? 我正在做什么,还是有更好的方法?

At the end of the day, I want to be able to re-use POGOs as grails domain objects, or export grails domain objects as POGOs. 最终,我希望能够将POGO用作grails域对象,或将grails域对象导出为POGO。

I believe you'll have to take care all the hibernate related artifact manually. 我相信您必须手动照顾所有与休眠有关的工件。 I've done something similar on a project where I created a Java lib of domain objects and shared it between Grails, desktop and Android projects. 我在一个创建域对象的Java库并在Grails,桌面项目和Android项目之间共享的项目上做了类似的事情。 It got tedious, but it worked. 它很乏味,但是有效。 All the annotations had to be done manually though. 但是,所有注释都必须手动完成。

Duplicating the data model is going to be much simpler. 复制数据模型将更加简单。

And that level of service interdependence means you're doing services wrong. 服务相互依赖程度意味着您做错了服务。

Version your services, and have APIs. 版本化您的服务,并具有API。 Use JSON to communicate of an API, and don't try any wacky schemes to share a data model. 使用JSON来交流API,不要尝试任何古怪的方案来共享数据模型。 If you're sharing a data model, you probably have one service, not two. 如果要共享数据模型,则可能只有一项服务,而不是两项。

You can set your own hibernate configuration in Grails. 您可以在Grails中设置自己的休眠配置。

So you can re-use your POGOs as something like grails domain objects (not sure about injected methods as findByX , addToYs , etc.). 因此,您可以将POGO用作grails域对象之类的东西(不确定注入的方法为findByXaddToYs等)。

Please see official documentation about hibernate in grails : http://grails.org/doc/latest/guide/hibernate.html 请在grails中查看有关休眠的官方文档: http : //grails.org/doc/latest/guide/hibernate.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM