我正在尝试在我的grails项目中重用我的hibernate域类,它包含两个域类User
和UserHistory
,其中User
类就像
class User {
@OneToMany(mappedBy = "user")
private Set<UserHistory> userHistories = new LinkedHashSet<UserHistory>();
//some fields and getter, setter
}
class UserHistory {
@ManyToOne
@JoinColumn(name = "USER_ID")
private User user;
//some fields and getter, setter
}
在UserController
我有一个像
User user = User.findByUserName("suganthan")
user.someField = "somevalue"
UserHistory history = new UserHistory(someField:"somevalue")
//Set<UserHistory> historySet = new HashSet<UserHistory>();
//historySet.add(history)
user.addToHistories( history ) // Error
user.save(failOnError: true)
但是行user.addToHistories( history )
正在抛出错误java.lang.UnsupportedOperationException
。有人可以帮我吗?