【问题标题】:Hibernate will not make indexes when creating tables from annotations从注解创建表时,Hibernate 不会创建索引
【发布时间】:2011-03-18 06:31:38
【问题描述】:

我正在使用带有 hbm2ddl.auto=update 的 hibernate,以便它会自动为我生成我的 oracle 表(我无意学习 oracle 的 sql)。

到目前为止,一切都很好,直到现在我试图让它创建一个索引。据我所知,我的注释是正确的:

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...
}

当我删除表并重新启动我的应用程序时,它会创建表而不是索引。有什么想法吗?

【问题讨论】:

标签: java oracle hibernate annotations indexing


【解决方案1】:

我在 Derby 上测试了你的代码,这是我在运行时得到的结果 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 被标记为已修复,而 @987654324 @ 已打开(!?),我的快速测试没有按预期工作。稍后我会更深入地研究,但我现在很困惑(尤其是HHH-1012)。

【讨论】:

  • 我读了一点,显然有这个bug,schemaupdate很好,只是当hbm2ddl.auto=update时出现问题。
猜你喜欢
  • 2016-07-17
  • 2018-11-19
  • 2012-02-01
  • 2019-03-31
  • 1970-01-01
  • 2020-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多