class Author {
String name
ArrayList<Book> books = []
static hasMany = [books: Book]
static mapping = {
books cascade: "all-delete-orphan"
}
}
尝试保存对象时发生错误。 “java.io.NotSerializableException”。有任何想法吗?我是否需要在类中实现Serializable?如果是这样,为什么?
答案 0 :(得分: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)
}
}