简体   繁体   中英

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. In another java/groovy project, I would like to use these domain objects. If I publish a plugin, it looks like only other grails applications can use the plugin.

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:

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.

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. 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. Use JSON to communicate of an API, and don't try any wacky schemes to share a data model. If you're sharing a data model, you probably have one service, not two.

You can set your own hibernate configuration in Grails.

So you can re-use your POGOs as something like grails domain objects (not sure about injected methods as findByX , addToYs , etc.).

Please see official documentation about hibernate in grails : http://grails.org/doc/latest/guide/hibernate.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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