Reputation: 133
I am having a problem setting up a List as a hasMany relationship to a belongsTo withing an extended class.
With a new Grails 2.4.4 app I have these 3 Domains:
An Author class having many books.
class Author {
List books
static hasMany = [books: Book]
}
A Book class which extends Content
class Book extends Content {
String foo
}
And Content, which has a number of common properties.
class Content {
String title
static belongsTo = [author: Author]
static constraints = {
sort: 'title'
}
}
When running this application I get the following exception:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: test.relationships.Book column: author_id (should be mapped with insert="false" update="false")
I only get this exception when I make books a List.
Upvotes: 0
Views: 573
Reputation: 3694
I think the problem is probably something to do with the fact you're saying that Author
has many Book
s, but the superclass of Book
, Content
, belongs to an Authur
.
What happens if you change your Content
and Book
classes to this:
class Content {
String title
static constraints = {
sort: 'title'
}
}
class Book extends Content {
static belongsTo = [author: Author]
String foo
}
or, alternatively, change your Author
class to this:
class Author {
List books
static hasMany = [contents: Content]
}
Upvotes: 0