1

我有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 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;

    ..

我的桌子:

        Column         |            Type             |  Modifiers                           
-----------------------+-----------------------------+-------------------------------
 id                    | integer                     | not null default 
 recs                  | xml                         | 
 recs_num              | integer                     | 
 details               | character varying(300)      | 
 d_stamp               | timestamp without time zone | default now()
 recs_detail_name      | text[]                   

|

数据库中的示例 recs_detail_name 如下所示:

{"TeleNav GPS Navigator","Photobucket for BlackBerry","Cellfire Mobile Coupons"}

有谁知道可能出了什么问题???谢谢

4

1 回答 1

1

ElementCollection 未映射到将序列化集合的单个列。它使用一个附加表进行映射,该表包含一个字符串列 (recs_detail_name) 和一个引用所属表主键的外键列。这当然在hibernate 文档中有所描述。

如果要将 Set 映射到单个列,则必须使用自定义用户类型。

于 2012-05-04T22:11:47.050 回答