views:

112

answers:

1

Hi, I'm using hibernate with hbm2ddl.auto=update so that it'll automatically generate my oracle tables for me (i've no intention of learning oracle's sql).

So far, so good, until now i'm trying to get it to create an index. As far as i can tell, i've made my annotations correctly:

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

When i drop the table and restart my app, it creates the table but not the index. Any ideas?

+1  A: 

I tested your code on Derby and here is what I get when running 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)

Works as expected. Can't try on Oracle right now though.

Tested with Hibernate EM 3.4.0.GA, Hibernate Annotations 3.4.0.GA, Hibernate Core 3.3.0.SP1.

Update: I realized I ran SchemaExport, not SchemaUpdate and confirm the index didn't get created when running SchemaUpdate with the versions of libraries mentioned above. So, while ANN-108 has been rejected as a dupe of HHH-1012, while HHH-1012 is marked as fixed, while HB-1458 is open (!?), my quick test didn't work as expected. I'll take a deeper look later but I'm very confused now (especially by HHH-1012).

Pascal Thivent
I've read a bit more, and apparently with this bug, schemaupdate is fine, it's just that when hbm2ddl.auto=update that the problem occurs.
Chris
But frigging kudos for trying my code out, thanks!
Chris