2012-05-04 274 views
1

我有區域經濟共同體模型映射到PostgreSQL中區域經濟共同體表,有些字段被宣佈爲設定,當我跑的代碼,它errorr扔爲:無法初始化集合

org.hibernate.exception.SQLGrammarException: could not initialize a collection: Recs._recsDetailName 
caused by: org.postgresql.util.PSQLException: ERROR: relation "recs__recsdetailname" does not exist 

我的區域經濟共同體模式:

@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[]     

|

在db樣本recs_detail_name是這樣的:

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

任何人都知道什麼可能是錯誤???謝謝

回答

1

一個ElementCollection沒有映射到一個列將被序列化的列。它使用一個附加表格進行映射,該表格包含String(recs_detail_name)的列和引用擁有表格的主鍵的外鍵列。這當然在hibernate documentation中描述。

如果要將Set映射到單個列,則必須使用自定義用戶類型。

相關問題