2015-07-20 61 views
2

我在我的項目中使用postgres數據庫和spring的hibernate。Hibernate實體中的Postgres數組

我只是想從數據庫,其中有數組類型列本身的表中的一些DATAS。

雖然我從表中獲取我收到以下錯誤。

ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: relation "reconcileprocess_bankstmtid" does not exist 

表結構如下該表

@Entity 
    @Table(name = "reconcile_process") 
    public class ReconcileProcess implements Serializable { 

     private static final long serialVersionUID = 1L; 

     @Id 
     @Column(name = "id") 
     Long id; 

     @Column(name = "comments") 
     String comments; 

     @Column(name = "fk_last_modified_by") 
     Long lastModifiedBy; 

     @Column(name = "last_modified_date") 
     Date lastModifiedDate; 

     @Column(name = "fk_transaction_ref") 
     String transactionRef; 

     @Column(name = "fk_remittance_transaction_fkey") 
     String remitTransactionRef; 

     @Column(name = "process_type") 
     String processType; 

     @Column(name = "reconcilled_date") 
     Date reconcilledDate; 

     @ElementCollection 
     @Column(name = "fk_bank_stmt_id") 
     List<Long> bankStmtId; 

回答

0

Hibernate不支持數據庫陣列(java.sql.Array

CREATE TABLE reconcile_process 
    (
     id bigserial NOT NULL, 
     comments character varying, 
     fk_last_modified_by bigint NOT NULL, 
     last_modified_date timestamp with time zone NOT NULL, 
     fk_remittance_transaction_fkey character varying, 
     fk_transaction_ref character varying, 
     process_type character varying, 
     reconcilled_date date, 
     fk_bank_stmt_id bigint[] 
    ) 

實體類。

你得到的錯誤,因爲Hibernate預計,List<Long> bankStmtId一個單獨的表(因爲你沒有明確指定表名,休眠假定的<entity name>_<property name>默認,從而reconcileprocess_bankstmtid)。

您可以切換到支持的方法用一個單獨的表,或者作爲解釋here,你可以嘗試編寫自定義用戶類型的數據庫列。