Using Grails Domain Classes Without Hibernate or GORM

In a Grails project, if I put my entities in the / domain folder, Grails automatically tries to use GORM / Hibernate to save. If I switch to another type of storage, say Mongo, Reddis, etc., Can I put my classes in a domain folder and implement my own save logic?

I disabled hibernate and domain in BuildConfig.groovy with excludes 'hibernate,domain' , but Grails is still complaining. Maybe I just need to put the domain classes in src/groovy/mypackage ...

+4
source share
1 answer

Grayl abuses the term "domain" slightly. Grails domain classes are persistent classes, regardless of whether they are persistent with Hibernate or NoSQL, or both. If you want to manage things yourself, put them in src / groovy.

If you want to use NoSQL, consider using one of the plugins, for example. mongodb or redis-gorm. If the NoSQL plugin is the only platinum plugin installed (i.e. you have uninstalled the Hibernate plugin), then the domain class in grails-app / domain will use this plugin. If you still have the Hibernate plugin installed, the default domain class will be the Hibernate domain class, but you can specify that it is a NoSQL domain class with the mapWith property, for example. static mapWith = "mongo" . This is described in the plugin docs.

You probably do not want to remove the domain plugin - I do not think that you have any benefit, and most likely it will break important functions.

+4
source

Source: https://habr.com/ru/post/1393563/


All Articles