2

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?

Chris
  • 39,719
  • 45
  • 189
  • 235
  • I had a look in the log, it all seemed fine. This is the only bit that stuck out at me: AnnotationConfiguration - Hibernate Validator not found: ignoring – Chris Jul 20 '10 at 05:59
  • 1
    Couple of known JIRAs on this http://opensource.atlassian.com/projects/hibernate/browse/HHH-1012 and https://forum.hibernate.org/viewtopic.php?f=9&t=955033&view=next – JoseK Jul 20 '10 at 06:08
  • Sounds like it's an old known bug. Bummer :( Would i be fair to assume that nobody actually uses hibernate to create their tables? Hence why nobody has gotten around to fixing this? – Chris Jul 20 '10 at 06:27
  • well people do use it - but see here for some previous discussions http://stackoverflow.com/questions/221379/hibernate-hbm2ddl-autoupdate-in-production and http://stackoverflow.com/questions/438146/hibernate-question-hbm2ddl-auto-possible-values-and-what-they-do – JoseK Jul 20 '10 at 07:40
  • Ok thanks for the links. Looks to me that nobody really uses this feature of hibernate. – Chris Jul 20 '10 at 23:13

1 Answers1

2

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
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 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 Jul 20 '10 at 23:12