【发布时间】:2016-09-20 14:00:25
【问题描述】:
我正在尝试在休眠中使用 Set。我不知道如何在 Set 表上写注解的问题。
@Entity
@Table(name="user_settings")
public class UserSettings {
@Id
@GeneratedValue
private int id;
private int userid;
protected Set<Integer>foreignLanguageId;
public UserSettings() {
}
public UserSettings(int userid, int nativeLanguageId,
Set<Integer> foreignLanguageId, Date birthday) {
this.userid = userid;
this.nativeLanguageId = nativeLanguageId;
this.foreignLanguageId = foreignLanguageId;
this.birthday = birthday;
}
@OneToMany
@JoinColumn(name="userid", nullable=false)// This annotation
public Set<Integer> getForeignLanguageId() {
return foreignLanguageId;
}
错误:
org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: user_settings, for columns: [org.hibernate.mapping.Column(foreignLanguageId)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314)...........
【问题讨论】:
-
我认为您应该将
foreignLanguageId变量的protected更改为private并与它一起使用 getter 和 setter,以便它可以在 hibernate 中映射。
标签: oracle hibernate annotations