1
class Author {

    String name

    ArrayList<Book> books = []

    static hasMany = [books: Book]

    static mapping = {
      books cascade: "all-delete-orphan"
    }

}

当我尝试保存对象时发生错误。“java.io.NotSerializableException”。有任何想法吗?我需要在课堂上实现 Serializable 吗?如果是这样,为什么?

4

1 回答 1

1

这是解决方案:

class Author {

    String name

    SortedSet books

    static hasMany = [books: Book]

    static mapping = {
      books cascade: "all-delete-orphan"
    }

}

   class Book implements Comparable {
      String title

      static belongsTo = [author: Author]

      int compareTo(obj) {
        title.compareTo(obj.title)
      }

   }
于 2012-06-27T20:16:42.153 回答