Convert CommentableObject to a simple non-abstract class and place it in grails-app/domain folder
Racker Vijay wrote:
Hello
I have the following domain model.
NewsArticle has many comments.
Event has many comments.
I would like to keep one table for the comments, and a table for NewsArticle and one for Event
To that end, this is what I did in Grails 1.1.1
abstract class CommentableObject {
SortedSet comments
static hasMany = [comments:Comment]
static mapping = {
tablePerHierarchy true
}
}
class NewsArticle extends CommentableObject {
String subject
}
class Event extends CommentableObject {
String title
}
class Comment implements Comparable {
Date date
String body
static belongsTo = [commentableObject:CommentableObject]
}
I keep getting this error on startup
org.hibernate.MappingException: An association from the table comment refers to an unmapped class: CommentableObject
However, if I make the superclass concrete, the error goes away.
what is the right way to map this type of associations