Mongodb 在Grails中是否可以加入mongo和mysql域?
我有一个域使用MySQL db,另一个域使用MongoDB。我能加入他们吗 例如: 上诉mongo域名Mongodb 在Grails中是否可以加入mongo和mysql域?,mongodb,grails,gorm,Mongodb,Grails,Gorm,我有一个域使用MySQL db,另一个域使用MongoDB。我能加入他们吗 例如: 上诉mongo域名 class Appeal { static mapWith = "mongo" Organization organization <=== MySQL domain ... } 没有,但你可以近似计算。在两个不同的关系数据库中连接两个表也会遇到同样的问题-每个表都有自己的SessionFactory,并且Hibernate或GORM不支持跨数据库或数据存储
class Appeal {
static mapWith = "mongo"
Organization organization <=== MySQL domain
...
}
没有,但你可以近似计算。在两个不同的关系数据库中连接两个表也会遇到同样的问题-每个表都有自己的SessionFactory,并且Hibernate或GORM不支持跨数据库或数据存储连接 若要进行近似计算,请存储其他表/文档的主键,并使用瞬态方法为您检索实例。这基本上就是Hibernate为您所做的——它存储外键值并根据需要自动加载实例
class Appeal {
static mapWith = "mongo"
void setOrganization(Organization organization) {
organizationId = organization.id
}
Organization getOrganization() {
organizationId ? Organization.get(organizationId) : null
}
static transients = ['organization']
Long organizationId
...
}
使用这种方法,您的代码将非常类似于两个表位于同一数据库中时的样子。当您访问该组织时,将使用以前保存的id从数据库中检索该组织
组织属性必须是暂时的,因为这样匹配的get/set对将被视为持久属性,正如您所看到的,这将失败。应该只保留id
Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'transactionManager': Cannot resolve reference
to bean '$primaryTransactionManager' while setting constructor
argument with key [0]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '$primaryTransactionManager': Cannot resolve
reference to bean 'sessionFactory' while setting bean property
'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory': Invocation of init method
failed; nested exception is org.hibernate.MappingException:
Association references unmapped class: lc.itgroup.education.dao.Appeal
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'transactionManager': Cannot resolve reference
to bean '$primaryTransactionManager' while setting constructor
argument with key [0]; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '$primaryTransactionManager': Cannot resolve
reference to bean 'sessionFactory' while setting bean property
'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory': Invocation of init method
failed; nested exception is org.hibernate.MappingException:
Association references unmapped class: lc.itgroup.education.dao.Appeal
class Appeal {
static mapWith = "mongo"
void setOrganization(Organization organization) {
organizationId = organization.id
}
Organization getOrganization() {
organizationId ? Organization.get(organizationId) : null
}
static transients = ['organization']
Long organizationId
...
}