Home Grails multi datasource domain issue
Reply: 1

Grails multi datasource domain issue

Eduardo Rodrigues
1#
Eduardo Rodrigues Published in 2013-03-07 22:18:42Z

I have a project which tables spread between 2 datasources. I'm configuring the code to access table as per 3.3.6 topic in grails documentations http://grails.org/doc/2.0.0.M2/guide/conf.html#dataSourcesAndEnvironments

Everything seems to be ok, but I got the following error

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 '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: br.com.fisgo.Provider

Caused by MappingException: Association references unmapped class: br.com.fisgo.Provider

Any idea on why do I get this error?

Regards.

I'll try it out. It won't be that simple because Company domain links back to Provider It will just require more efort

class Company {
    String name
    String cnpj
    String email
    Address address
    Phone phone
    String registration
    String source

    Set provider = new HashSet<Provider>()

    static hasMany = [provider: Provider]
Burt Beckwith
2#
Burt Beckwith Reply to 2013-03-07 22:47:27Z

You should use newer docs, e.g. http://grails.org/doc/latest/guide/conf.html#dataSourcesAndEnvironments

It looks like you're trying to link across datasources. This isn't possible since each DataSource has a separate SessionFactory, and they cannot work directly together. The same problem happens when you use Hibernate and a NoSQL GORM plugin.

You can mimic it easily enough though. Given a domain class Foo that needs a reference to Provider, you can persist the foreign key and look it up on-demand (and this is really what Hibernate does for you when you join between two domain classes):

class Foo {
   Long providerId

   Provider getProvider() {
      providerId ? Provider.get(providerId) : null
   }
   void setProvider(Provider provider) {
      providerId = provider.id
   }
   static transients = ['provider']
}

Since Groovy treats getter/setter pairs as a property, you would use it like a "real" link:

def foo = ...
def bar = foo.provider.bar
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.407702 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO