简体   繁体   English

仅在某些域类上具有GORM的Grails或具有多个数据库的Grails项目

[英]Grails with GORM only on some domain classes or Grails project with multiple DBs

I have a Grails application using some proprietary NoSQL DB. 我有一个使用一些专有的NoSQL DB的Grails应用程序。 I have the hibernate plugin disabled. 我禁用了休眠插件。 I have many domain classes with lots of constrains defined and with own implementation of save() and get() that calls some java services that are dealing with persistence. 我有许多域类,它们定义了很多约束,并且具有save()和get()自己的实现,这些实现调用一些处理持久性的Java服务。 Everything is working fine. 一切正常。

But now, we have a deal with a client to save some things directly into their MySQL DB. 但是现在,我们与客户达成协议,将一些东西直接保存到他们的MySQL数据库中。 Simple thing at first. 一开始很简单。 I configured their DB connection, enabled hibernate plugin and I created a new domain class to deal with that. 我配置了他们的数据库连接,启用了hibernate插件,并创建了一个新的域类来处理该问题。 Everything is working fine in a test app, but when i enabled the hibernate plugin into main project, is not starting anymore. 在测试应用程序中一切正常,但是当我将hibernate插件启用到主项目中后,就无法再启动了。

Hibernate is trying to map all domains to tables in the DB and of course they do not exists (because are using the NoSQL DB). Hibernate尝试将所有域映射到数据库中的表,并且它们当然不存在(因为正在使用NoSQL DB)。

My questions is: Can I enable hibernate just for several domains? 我的问题是:我可以只为几个域启用休眠吗? Or can I instruct some domain to not use hibernate/gorm? 还是可以指示某些域不使用休眠/休眠? Or per package? 还是每包? How is Grails handling multiple DBs for same project? Grails如何为同一项目处理多个DB?

You can set multiple datasources to take care of NoSQL db and MySQL db. 您可以设置多个数据源来处理NoSQL db和MySQL db。 Then you will be left with the domain objects which uses Java services for persistence. 然后,您将剩下使用Java服务进行持久化的域对象。

You are using constraints on them but are you leveraging the Gorm Static API like dynamic finders on them? 您正在对它们使用约束,但是您是否像对它们的动态查找器一样利用Gorm Static API? To abstract them from hibernate implementation, I would try moving them from grails-app/domain to src/groovy or use static mapWith = 'none' in classes. 为了将它们从休眠实现中抽象出来,我将尝试将它们从grails-app/domain移至src/groovy或在类中使用static mapWith = 'none'

You can configure this with the mapWith option in the domain class. 您可以使用域类中的mapWith选项进行配置。

Related SO question: Is it possible in grails to disable persistence of a domain class? 相关的SO问题: 是否有可能禁用域类的持久性?

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

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