在创建索引数据库使用Hibernate @index注释 [英] Creating Indexes on DB with Hibernate @Index Annotation

查看:1788
本文介绍了在创建索引数据库使用Hibernate @index注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有注解驱动的休眠capabilies在我的项目。

I have annotation-driven hibernate capabilies on my project.

现在我想建立一个多列的索引。我现在的列定义为

Now I want to create an index over a column. My current column definition is

@NotNull
@Column(name = "hash")
private String hash;

和我添加 @index 注释在这里。

@NotNull
@Column(name = "hash")
@Index(name="hashIndex")
private String hash;

然后DROP TABLE,然后重新启动Tomcat服务器。服务器实例化后,在创建表,但我不能看到下面的查询新指标。

and then DROP TABLE and restart Tomcat server. After the server is instantiated, the table is created but I can't see new index on following query.

SHOW INDEX FROM tableName

预期构造表用新的索引。我使用的是InnoDB与MySQL。

It is expected to construct table with new index. I am using InnoDB with MySQL.

推荐答案

有趣的是,在我的Hibernate配置我使用 hibernate.hbm2ddl.auto =更新

Interestingly, in my Hibernate configuration I was using hibernate.hbm2ddl.auto=update.

这一次修改现有的数据库。我是手动删除表 tableName值并重新启动Tomcat和表已经建成,但没有被创建的索引。

This one modifies an existing database. I was manually DROPping the table tableName and restarting Tomcat and the table had been constructed but index was not being created.

不过,我做了Web应用程序时的每个实例 hibernate.hbm2ddl.auto =创建这重新创建数据库时,放弃我所有的数据库和重建背部和-hell耶 - !我的新指数已创建

However, I made hibernate.hbm2ddl.auto=create which re-creates database upon each instantiation of webapp, it dropped all my database and rebuilt back and -hell yeah- my new index has been created!

这篇关于在创建索引数据库使用Hibernate @index注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆