I am new to grails and I am currently using grails 3.0. I was trying to have the one-to-many relation between two tables across different databases. I have referred almost all the links and grails documentation, but couldn't figure out if this scenario is at all possible. I have sample code written, which works perfectly if the two tables from two different databases are independent. i.e. there is no relation/mapping or references. I see the data has been saved properly in each table through the sample.
If I try to map the tables with say one-to-many relation (typical Book-Author domain class example), it fails. I get the mapping exceptions
. I also tried the suggested workaround of overriding the get
and set
methods.
Are there any links or sample code which will guide me? Here is my code without getter
and setter
:
class Book {
Long id
String title
String author
Users user
static constraints = {
title(blank: false)
author(blank: false)
}
}
class Users {
String username
String address
static hasMany = [books: Book]
static constraints = {
username(blank: false)
address(blank: false)
}
static mapping = {
datasource 'lookupusers'
}
}