JPA 2.1带有函数的列的索引注释 [英] JPA 2.1 Index annotation for columns with a function
问题描述
@Entity
@Table(name = MY_TABLE,索引= {
@Index(name =idx_user_name,columnList =name),
@Index(name =idx_user_email,columnList =email)
} )
这很好,但是当我想像这样创建一个索引时会发生什么: p>
CREATE INDEX ON my_table(lower(name));
如果我使用以下注释,将得到 AnnotationException $ c $
pre $ lt; code> @Index(name =idx_lower_name,columnList =lower(name))
我希望通过Hibernate + JPA 2.1创建索引来发布我的项目。是否可以通过索引注释来应用函数?
或者,我应该在部署中运行一个SQL脚本,以通过SQL自己添加这些索引?
我可能只是格式化 columnList
错误,或者可能有一个字段未在文档中描述I' m缺少。
在JPA 2.1中不能使用基于函数的索引。
JPA提供了从特定数据库中抽象的方法。每个数据库都有自己的FBI实现,可以差别很大。
因此,它不是标准的一部分。
我窥视了Hibernate代码,看看FBI是否有未公开的功能。不幸的是,只有基于列的索引是支持。
您应该在部署时运行SQL脚本来创建索引。 p>
In my Hibernate project, I add indices like so:
@Entity
@Table(name="MY_TABLE", indexes = {
@Index(name = "idx_user_name", columnList = "name"),
@Index(name = "idx_user_email", columnList = "email")
})
Which works just fine, but what happens when I want to make an index like this:
CREATE INDEX ON my_table (lower(name));
If I use the following annotation I get an AnnotationException
:
@Index(name = "idx_lower_name", columnList = "lower(name)")
I wish to ship my project with the indices made via Hibernate + JPA 2.1. Is it possible to apply functions via the Index annotation?
Or should I just run an SQL script on deployment to add these indices myself via SQL?
I could just be formatting the columnList
wrong, or there could be a field not described in the documentation I'm missing.
It is not possible to use a function based index in JPA 2.1.
JPA provides means to abstract from a specific database. Every database has its own implementation of FBI which can vary greatly. Hence, it is not part of the standard.
I peeked into the Hibernate code to see whether there might be an undocumented feature for a FBI. Unfortunately, only column based indexes are supported.
You should run a SQL script on deployment to create your index.
这篇关于JPA 2.1带有函数的列的索引注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!