2
votes

Just for flexibility and not to be tied up with Grails, I wish to create domains on a separate java project and import the domain classes in Grails project. Is that possible? I am thinking the Java project will just contain POJO and maybe hibernate mapping to database.

I wish to be able to use the usual save delete and find* functionalities if possible.

2

2 Answers

4
votes

You need to create a separate plugin project which contains the domain classes. And if you want to use it in your grails project then just add following in your BuildConfig.groovy

grails.plugin.location.YourDomainClassProjectName= "../YourDomainClassProjectName"

And add that project from build path. Right click on project from navigator - > Properties -> Java Build Path -> Project ... and add your project here.

3
votes

You can use also plain Java project as a domain model - see grails.org/doc/latest/guide/single.html#hibernate

Basically you put there your domain classes together with Hibernate mapping (XML or annotation-based) and pack it into jar, which is then added as a dependency to the grails app.

Your domain classes will be enhanced with standard GORM methods (findBy, save..) just as if they were GORM domain classes. We have used this model a long time in our projects.