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