4

My tools -> Java 8, JPA 2.1 and Hibernate 4. Im using just JPA2.1 annotations.

The code in the dock ->

@Entity
@Table(indexes = { @Index(name = INDEX_PK, columnList = ID) })
public class Invoice {

 @Id
 @GeneratedValue(strategy = GenerationType.AUTO, generator = DEF_GEN_NAME)
 @SequenceGenerator(sequenceName = DEF_SEQUENCE_NAME, name = DEF_GEN_NAME, allocationSize =   
 ALLOCATION_SIZE)
 @Column(name = ID)
 private Long id = 0L;

}

When schemma is being created by Hibernate (hbm2ddl="create-drop"), i get the following Oracle error:

Hibernate: create index INVOICE_ID_PK on Invoice (ID)
sep 14, 2014 7:00:53 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: create index INVOICE_ID_PK on Invoice (ID)
sep 14, 2014 7:00:53 AM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: ORA-01408: such column list already indexed

Searching for this issue y found that index on primary keys are default generated by Oracle itself, Hibernate is unaware of this behavior, fact is that hibernate first create table Invoice, so Oracle automatically create a index called sysXXX (example: SYS_C0011010) for id on tha table Invoice. After all tables are created Hibernate begin to create indexes, then Oracle throw an error for
duplicating an index on same column ID

Is there a way to alter this behavior to create the index and table in same SQL statement by Hibernate?..any walkaround?

Thanks!

ame-h
  • 1,617
  • 1
  • 12
  • 13
  • 1
    You don't need to create a separate index on your primary key column as the index is automatically created. If you were using normal DDL you could name the index as you wish, but since you're using Hibernate it appears that option isn't open to you. Best of luck. – Bob Jarvis - Слава Україні Sep 14 '14 at 17:03
  • @BobJarvis maybe i will go with just DDL, i saw a couple posts [link](http://stackoverflow.com/a/15328062/2033885) talking about Maven plugins to generate DDL script from JPA Entities, thanks! – ame-h Sep 15 '14 at 05:24

0 Answers0