« Return to Thread: composite 1-many association with multiple domain objects

composite 1-many association with multiple domain objects

by Racker Vijay :: Rate this Message:

Reply to Author | View in Thread

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

 « Return to Thread: composite 1-many association with multiple domain objects