Grails - 使用hibernate域类的问题

时间:2014-08-30 11:03:07

标签: java hibernate grails one-to-many has-many

我正在尝试在我的grails项目中重用我的hibernate域类,它包含两个域类UserUserHistory,其中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。有人可以帮我吗?

0 个答案:

没有答案