Hibernate 无法初始化集合
我将recs模型映射到postgresql中的recs表,一些字段被声明为已设置,当我运行代码时,它抛出的错误为:Hibernate 无法初始化集合,hibernate,Hibernate,我将recs模型映射到postgresql中的recs表,一些字段被声明为已设置,当我运行代码时,它抛出的错误为: org.hibernate.exception.SQLGrammarException: could not initialize a collection: Recs._recsDetailName caused by: org.postgresql.util.PSQLException: ERROR: relation "recs__recsdetailname" does n
org.hibernate.exception.SQLGrammarException: could not initialize a collection: Recs._recsDetailName
caused by: org.postgresql.util.PSQLException: ERROR: relation "recs__recsdetailname" does not exist
我的recs型号:
@Entity
@Table(name = "RECS", uniqueConstraints = @UniqueConstraint(columnNames = "id"))
public class Recs implements Serializable, Cloneable {
/**
* Serialized version unique identifier.
*/
private static final long serialVersionUID = -7316874431882307750L;
@Id
@Column(name = "id")
private int _id;
@Basic
@Column(name = "recs_num")
private int _recsNum;
@Basic
@Column(name = "details")
private String _details;
@Column(name = "d_stamp")
private Date _timeStamp;
@ElementCollection(fetch = FetchType.EAGER)
@Column(name = "recs_detail_name")
private Set<String> _recsDetailName;
..
|
db中的示例记录详细信息名称如下所示:
{"TeleNav GPS Navigator","Photobucket for BlackBerry","Cellfire Mobile Coupons"}
有人知道可能出了什么问题吗???感谢ElementCollection没有映射到将序列化集合的单个列。它使用一个附加表进行映射,该表包含一列字符串(recs_detail_name)和一个外键列,外键列引用所属表的主键。这当然在本手册中有所描述
如果要将集合映射到单个列,则必须使用自定义用户类型。ElementCollection未映射到将序列化集合的单个列。它使用一个附加表进行映射,该表包含一列字符串(recs_detail_name)和一个外键列,外键列引用所属表的主键。这当然在本手册中有所描述 如果要将集合映射到单个列,则必须使用自定义用户类型
{"TeleNav GPS Navigator","Photobucket for BlackBerry","Cellfire Mobile Coupons"}