How can I ask Hibernate to create an index on a foreign key (JoinColumn)?

岁酱吖の 提交于 2019-12-06 06:17:32

Try an @Index annotation.

@Index(name="user_type_index")

There is also an @IndexColumn annotation used with join tables, but it doesn't seem to actually create an index, but controls which field defines order in list semantics.

The @Index column in this context does seem to create an index on the join table.

I'm dealing with a similar issue and I've found that some dialects will automatically index foreign keys and others wont.

Hibernate Dialect class and all subclasses which do not override the getAddForeignKeyConstraintString method (Oracle, SQL Server, etc) will not create an index on the foreign key.

MySQLDialect overrides that method and adds an index to every foreign key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!