I'm having trouble making work a mapping for a legacy database that for me is read only, I have a class Client that belongs to ThirdParty and ThirdParty has one Client.
The tables look like this:
Client ThirdParty
--------------------- --------------------
third_party_rowid (key) rowid (key)
Client doesn't have its own id, and ThirdParty doesn't have a reference to Client, so when I try mapping Client I get a lot of errors:
If I try mapping both the id of Client and the ThirdParty of Client to the same column I get a duplicated column error
static mapping = {
datasource 'xxxxx'
table 'clients'
version false
id column: 'third_party_rowid'
thirdParthy column: 'third_party_rowid'
....
}
If I try giving the id of Client the name 'thirdParhy' I get an unknown type error
static mapping = {
datasource 'xxxxx'
table 'clients'
version false
id name: 'thirdParthy'
thirdParthy column: 'third_party_rowid'
....
}
If I try don't give id a parameter I get an invalid id error
static mapping = {
datasource 'xxxxx'
table 'clients'
version false
thirdParthy column: 'third_party_rowid'
....
}
I'm running out of ideas, can someone help me map this?
Thanks!
I found out the problem!, hibernate needs one of the duplicated columns to be mapped with insert="false", update="false"
To do that on grails you have to add that to the mapping, like this:
static mapping = {
datasource 'xxxxx'
table 'clients'
version false
id column: 'third_party_rowid'
thirdParthy column: 'third_party_rowid', insertable: false, updateable: false
....
}