使用BaseClass和tablePerHierarchy false导致多对多

时间:2018-12-02 22:39:01

标签: grails many-to-many

基于official example,以下示例将失败,并显示

org.hibernate.AssertionFailure: Table mm_author_books not found

在tablePerHirachy设置为false的情况下,如何在grails中映射多对多关系?

 class SomeBase {

    static mapping = {
        tablePerHierarchy false

    }
 }

class Book extends SomeBase {

    String title

    static belongsTo = Author

    static hasMany = [authors: Author]

    static mapping = {
        authors joinTable: [name: "mm_author_books", key: 'mm_book_id' ]
    }
}

class Author extends SomeBase {

    String name

    List books

    static hasMany = [books: Book]

    static mapping = {
        books joinTable: [name: "mm_author_books", key: 'mm_author_id']
    }
}

1 个答案:

答案 0 :(得分:0)

如果您使用tablePerConcreteClass true而不是tablePerHierarchy false,它将起作用。由于我们不使用抽象基类,因此两种映射策略都将创建相同的数据库映射。因此,我认为这是当前gorm堆栈中的错误。我发布了一个问题:https://github.com/grails/gorm-hibernate5/issues/112