I'm trying to use grails with an existing old style legacy db. I have composite keys everywhere (PK and FK) and... more FK sharing the same table column. An example:
All tables shares the "company" value.
class SalesOrder implements Seria开发者_开发百科lizable{
...
static hasMany = [items: SalesOrderItem]
static mapping = {
table 'MYORDERTABLE'
id composite: ["company", "orderId"], generator: "assigned"
Than my sales order items:
class SalesOrderItem implements Serializable{
....
Material mat
static belongsTo = [order: SalesOrder]
static mapping = {
table 'MYORDERITEMSTABLE'
id composite: ["order", "lineNumber"], generator: "assigned"
lineNumber column: 'ITEMNUMBER'
columns {
order { column name:'COMPANY'
column name:'ORDERNUMEBR' }
}
All the previous code works (only with grails 2.0 M1). My "order" has a composite PK (company+orderId), my "orderLine" has a composite PK (company+orderId+orderLineId).
The problems come when I have other attributes with composite keys that shares the "company" attribute as one element of the FK, like
columns{
mat { column name: 'COMPANY', insertable:false, updateable:false
column name: 'MATTYPE'
column name: 'MATCODE'
column name: 'MATCODEEXT1'
column name: 'MATCODEEXT2'
}
}
This does not work, the error that comes out is
Repeated column in mapping for entity: SalesOrderItem
column: COMPANY (should be mapped with insert="false" update="false")
And I'm stuck right here. If it was just one case, I would use some cheap & dirty workaround but I have plenty of cases like this.
Do you have any suggestion? Hint? Solution? Any help is appreciated?
Thanks, Lorenzo
Update
I have found the following post with basically the same question about hibernate:
should-hibernate-be-able-to-handle-overlapping-foreign-keys
and it seems that it is still an unresolved issue:
hibernate jira
no hibernate, no gorm I suppose. As for a workaround I'm thinking on using the events aferLoad, beforeInsert, beforeUpdate to load/update the domain classes linked with this FK's.
精彩评论