2010-07-20 124 views
2

我正在使用hibernate和hbm2ddl.auto = update這樣它會自動爲我生成我的oracle表(我無意學習oracle的sql)。從註釋創建表時,Hibernate不會創建索引

到目前爲止,這麼好,直到現在我試圖讓它創建一個索引。據我所知,我已經正確地做了我的註釋:

package data; 
import javax.persistence.*; 
import org.hibernate.annotations.Index; 

@Entity 
@Table(name="log_entries") 
@org.hibernate.annotations.Table(appliesTo="log_entries", 
    indexes = { @Index(name="idx", columnNames = {"job", "version", "schedule", "dttmRun", "pid" }) }) 
public class LogEntry { 
    @Id @GeneratedValue 
    Long id; 
    String job; 
    String version; 
    String schedule; 
    String dttmRun; 
    int pid; 
    String command; 
    int duration; 

    // getters and setters... 
} 

當我刪除該表並重新啓動我的應用程序,它創建的表,但不是指數。有任何想法嗎?

+0

我看了一下日誌,看起來一切正常。這是唯一突出的一點: AnnotationConfiguration - 找不到Hibernate Validator:忽略 – Chris 2010-07-20 05:59:47

+1

這個http://opensource.atlassian.com/projects/hibernate/browse/HHH-1012和https:/ /forum.hibernate.org/viewtopic.php?f=9&t=955033&view=next – JoseK 2010-07-20 06:08:01

+0

聽起來像是一個古老的已知錯誤。無賴:( 我會公平地假設沒有人真正使用hibernate來創建他們的表嗎?爲什麼沒有人得到解決這個問題呢? – Chris 2010-07-20 06:27:15

回答

2

我測試你對德比的代碼,這裏是運行 SchemaUpdate SchemaExport當我得到什麼:

drop table log_entries 

create table log_entries (
    id bigint not null, 
    command varchar(255), 
    dttmRun varchar(255), 
    duration integer not null, 
    job varchar(255), 
    pid integer not null, 
    schedule varchar(255), 
    version varchar(255), 
    primary key (id) 
) 

create index idx on log_entries (job, version, schedule, dttmRun, pid) 

按預期工作。儘管現在不能嘗試Oracle。

經過Hibernate EM 3.4.0.GA,Hibernate Annotations 3.4.0.GA,Hibernate Core 3.3.0.SP1的測試。

更新:我意識到我跑SchemaExport,不SchemaUpdate並確認指標並沒有生成與上述庫的版本上運行SchemaUpdate時。所以,雖然 ANN-108 已被否決的 HHH-1012 愚弄的人,而 HHH-1012 被標記爲固定的,而HB-1458是開放的(!?),符合市場預期我的快速測試沒有工作。我稍後會深入探討,但現在我很困惑(尤其是HHH-1012)。

+0

我讀了一點,顯然有了這個bug,schemaupdate很好,只是當hbm2ddl.auto =更新發生問題時 – Chris 2010-07-20 23:12:34

+1

但是爲了嘗試我的代碼而感到非常榮幸,謝謝! – Chris 2010-07-20 23:12:49