2016-04-21 20 views
2

我創建了一個實體對象,並用@Index註解對它進行了註釋。應用程序工作,但在數據庫中不存在我想要的索引。我嘗試了JPA和Hibernate註釋,但都沒有運氣。這個類放置在Spring引導1.3.3.RELEASE應用程序中。在Maven依賴關係中,我看到了hibernate-core-4.3.11.Final.jar,它映射到PostgreSQL 9.4.5。我在application.properties文件中爲spring.jpa.hibernate.ddl-auto嘗試了不同的值,例如創建,創建,刪除,更新甚至從數據庫中刪除表。春季啓動,休眠 - 如何獲得實體屬性的索引?

請幫助:如何使應用程序創建索引使用註釋?

更新

我打與相同配置創建的註釋和索引。我不明白什麼不同。我只發現在停止我的應用程序和在數據庫中創建的表之後,需要一些時間才能在pgAdmin中查看索引更新。它看起來像一些緩存更新左右。另外我發現不能爲不同的表創建具有相同名稱的索引。仍然無法得到發生的事情。

更新

這裏的實體類

import java.util.Date; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.Index; 
import javax.persistence.ManyToOne; 
import javax.persistence.Table; 
import org.jsoup.nodes.Element; 

@Entity 
@Table(indexes = { @Index(name = "job_id_idx", columnList = "job_id")}) 
public class JobLifeTime { 

    @Id 
    @GeneratedValue(strategy=GenerationType.AUTO) 
    private Long code; 

    @Column(name="job_id", length=24) 

    private String targetJobCode; 
    @ManyToOne() 
    private ScraperTask scraperTask; 
    @Column(name="salary_low") 
    private Integer salaryMin; 
    @Column(name="salary_high") 
    private Integer salaryMax; 
    @Column(name="scrape_timestamp") 
    private Date scrapeTimestamp; 
    @Column(name="remove_timestamp") 
    private Date removeTimestamp; 

    public JobLifeTime(){} 

    //getters and setters ... 
} 
+0

我上面,你說Application.properties注意到以上。那只是一個錯字嗎?該文件應該命名爲application.properties(注意小寫),並且它必須放在src/main/resources下,以便Spring自動識別它 –

+0

是的右小寫。應用程序看到這個文件,並從它配置。寫作時我只想念這裏。將編輯帖子。 – Pavlo

+0

也許這有助於http://stackoverflow.com/questions/22816817/hibernate-create-index – RubioRic

回答

0

使用上的場@index註釋,而不是類