2017-04-12 53 views
2

我想添加索引到我現有的實體,在特定的列上非常實用。下面的文檔我寫了類似的東西:EclipseLink - 將索引添加到Postgress

1.first way 
@Entity 
@Table(name = "potatoe", schema = "mySchema") 
public class Potatoe { 
(...) 
@Index(name = "knife", table = "potatoe", schema = "mySchema") 
    private String origin; 
(...) 
} 

2.second way 
@Entity 
@Table(name = "potatoe", schema = "mySchema") 
@Index(name = "knife", columnNames = "origin", table = "potatoe", schema = "mySchema") 
public class Potatoe { 
(...) 
    private String origin; 
(...) 
} 

3. third way(pure jpa) 
    @Entity 
    @Table(name = "potatoe", schema = "mySchema", indexes = {@javax.persistence.Index(name = "knife", columnList = "origin")}) 
    public class Potatoe { 
    (...) 
     private String origin; 
    (...) 
    } 

但沒有工作,指數沒有創建。我總是gotted例外:通過創建的EclipseLink

Caused by: org.postgresql.util.PSQLException: ERROR: error in syntax or/in near "."

查詢

CREATE INDEX myschema.knife ON potatoe (ORIGIN)]]

,我不知道他爲什麼改變指數的名稱。爲什麼eclipseLink添加點名稱的模式?我想這是「。」在索引造成問題的名稱,但我不知道如何刪除這個。

我正在使用eclipselink ver 2.5.0和postgresql ver 9.1-901。

編輯// 當我刪除屬性「模式」,創造的EclipseLink正確查詢:

CREATE INDEX knife ON potatoe (ORIGIN)]]

,但問題是,我必須定義模式,因爲我有一些。所以如果沒有定義的模式,它關於關係的錯誤(關係不存在)。所以它是真的,因爲我的默認關係不是「myschema」。

我檢查的Postgres和工作查詢是像下面,但我不知道如何產生的:

CREATE INDEX knife ON myschema.potatoe (ORIGIN)

有人有想法?

+0

似乎是一個錯誤 - 指數不應該有架構名稱預先準備,但這個表應該 - 一路走去 –

+0

也許嘗試' ''@Index(name =「knife」,columnNames =「origin」,table =「potatoe」)'''?.. –

+0

@Vao Tsun我試過我認爲所有這種變化的註釋和所有沒有作品:/ – newOne

回答