Mapping one-to-many Relationship in GGTS

时间:2015-06-30 13:30:56

标签: hibernate grails gorm one-to-many ggts

I'm new and self learning, so please bear with me...

I've racked my brain for days on this error I'm getting when trying to map a one-to-many relationship between my Personnel class and my Probdata class in GGTS.

Here are some code snippets:

package benefitsapplication

class Personnel {

static hasMany = [probations:Probdata,probterms:Probdata]
static mappedBy =  [probations:"lineNumber", probterms:"paysrId"]

// static hasMany = [probations:Probdata] // static mappedBy = [probations:"lineNumber"]

String lineNumber
String paysrId
    ....


package benefitsapplication

class Probdata {

static belongsTo = [person:Personnel]


String lineNumber
String reportNumber
String paysrId
    ...

I tried mapping using 2 objects (composite key) at first, then tried using one. Each time, I get the same error:

"Error loading plugin manager: Non-existent mapping property [lineNumber] specified for property [probations] in class [benefitsapplication.Personnel]"

Then GGTS says to use --stacktrace for details (which I have no clue where that is or how to run it)

Based off of my own research, which none of my books cover, the Mapping() method is always used to map between classes, but the MappedBy() method isn't necessarily used.

Is that, in short, what I'm missing? The Mapping() method? And should I also put it in the child table? Or not necessarily? Do I need the MappedBy() method?

Related question - Initially, I used my "Probations" identifier for both objects. In my trying to troubleshoot, I changed that. Does that even matter?

1 个答案:

答案 0 :(得分:0)

所以我在Grails in Action书的出版商运营的论坛中提出了这个问题。作者回应并非常有帮助。

他解释说MappedBy()和Mapping()方法专门处理同一类类型的类中的对象。例如,如果我有2个Personnel类型的对象。

MappedBy()和Mapping()不适用于String类型的对象,这些对象不是域类型。