[英]Grails/GORM Legacy DB One-to-Many mappedBy issue
I have a legacy DB with rather simple structure. 我有一个结构相当简单的旧式数据库。 I have "rolls" that contain "rollTotals".
我有包含“ rollTotals”的“卷”。 Roll has a primary key of "rollID" and RollTotals have a composite key on "rollID" and "category".
Roll的主键为“ rollID”,而RollTotals的组合键为“ rollID”和“ category”。
So in Grails, I have: 所以在Grails中,我有:
class Roll {
Integer id
...
static hasMany = [ rollTotals: RollTotal ]
static mapping = {
table('rolls')
id(column:'rollID')
version false
...
}
}
and 和
class RollTotal implements Serializable {
Integer rollId
Integer category
...
static belongsTo = [ Roll ]
static mapping = {
table('rolltotals')
id composite:['rollId', 'category']
version false
rollId(column:'rollID')
category(column:'category')
...
}
These mappings work fine individually but when I put the hasMany, it says: 这些映射可以单独正常工作,但是当我放置hasMany时,它表示:
Missing table: rolls_rolltotals
缺少表格:rolls_rolltotals
So I figured it needed to know which column to use as foreign key, so I added to Roll: 因此,我认为它需要知道将哪一列用作外键,因此我将其添加到Roll中:
static mappedBy = [rollTotals: "rollId" ]
It says: 它说:
org.codehaus.groovy.grails.exceptions.GrailsDomainException: Non-existent mapping property [rollId] specified for property [rollTotals] in class [class Roll]
org.codehaus.groovy.grails.exceptions.GrailsDomainException:为类[class Roll]中的属性[rollTotals]指定了不存在的映射属性[rollId]
I tried with rollID (as the column name) but get the same result. 我尝试使用rollID(作为列名),但得到相同的结果。
Any idea as to how I can link these tables ? 关于如何链接这些表的任何想法吗?
Try changing belongsTo for RollTotal to: 尝试将RollTotal的belongsTo更改为:
static belongsTo = [roll: Roll]
and add to mapping for RollTotal 并添加到RollTotal的映射
roll(column:'rollId')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.