Oracle 如何使用@index JPA注释在主键上设置索引名?
我的工具->Java8、JPA2.1和Hibernate4。我只使用JPA2.1注释 坞中的代码->Oracle 如何使用@index JPA注释在主键上设置索引名?,oracle,hibernate,jpa,oracle11g,jpa-2.1,Oracle,Hibernate,Jpa,Oracle11g,Jpa 2.1,我的工具->Java8、JPA2.1和Hibernate4。我只使用JPA2.1注释 坞中的代码-> @Entity @Table(indexes = { @Index(name = INDEX_PK, columnList = ID) }) public class Invoice { @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = DEF_GEN_NAME) @SequenceGenerator(sequ
@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;
}
当Hibernate创建schemma(hbm2ddl=“create drop”)时,我得到以下Oracle错误:
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
搜索此问题时,y发现主键上的索引默认由Oracle本身生成,Hibernate不知道此行为,事实是Hibernate首先创建表发票,所以Oracle会自动为表发票上的id创建一个名为sysXXX(例如:SYS_C0011010)的索引。 在创建所有表之后,Hibernate开始创建索引,然后Oracle为
在同一列ID上复制索引 有没有办法通过Hibernate在同一个SQL语句中创建索引和表来改变这种行为?有没有详细介绍
谢谢 您不需要在主键列上创建单独的索引,因为索引是自动创建的。如果您使用的是普通的DDL,您可以根据需要命名索引,但由于您使用的是Hibernate,因此该选项似乎对您不开放。祝你好运。@BobJarvis也许我会选择DDL,我看到了一些关于Maven插件从JPA实体生成DDL脚本的帖子,谢谢!