gpt4 book ai didi

grails - java.io.NotSerializableException将hasMany更改为ArrayList

转载 作者:行者123 更新时间:2023-12-02 14:45:43 24 4
gpt4 key购买 nike

class Author {

String name

ArrayList<Book> books = []

static hasMany = [books: Book]

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

}

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

最佳答案

解决方法如下:

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)
}

}

关于grails - java.io.NotSerializableException将hasMany更改为ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11228050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com