简体   繁体   English

通过Hibernate 4.3.5 / JPA 2.1创建date_trunc索引

[英]Creating date_trunc index via Hibernate 4.3.5 / JPA 2.1

I want to create index like this below: 我想创建如下所示的索引:

CREATE INDEX idx_foo_req_date
ON foo
USING btree
(date_trunc('day'::text, req_date));

How/Can I create it via java hibernate annotations? 如何/我可以通过java hibernate注释创建它?

I have already read about @Index annotation to use it like: 我已经阅读了有关@Index注释的内容,如下所示:

@Table(name = "foo", indexes = { @Index(name = "idx_foo_req_date", columnList = "req_date") })

but it will create smth like this: 但它会像这样创建smth:

CREATE INDEX idx_foo_req_date
ON foo
USING btree
(req_date);

UPDATE: 更新:

I thought maybe it is pretty flexible and simple and i have tried: 我想也许它非常灵活和简单,我尝试过:

@Table(name = "foo", indexes = { @Index(name = "idx_foo_req_date", columnList = "date_trunc('day'::text, req_date)") })

However org.hibernate.AnnotationException has been thrown, complaining about columns in columnList . 但是抛出了org.hibernate.AnnotationException ,抱怨columnList列。

Hibernate uses the JPA @Index annotation which doesn't support function-based indexes. Hibernate使用JPA @Index注释,它不支持基于函数的索引。

You'd better use Flyway and keep your schema migration in incremental scripts. 您最好使用Flyway并在增量脚本中保留模式迁移。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Springboot Hibernate & JPA 和 Native Queries (Group by PostgreSQL date_trunc) 可分页问题 - Springboot Hibernate & JPA and Native Queries (Group by PostgreSQL date_trunc) pageable problem 使用 JPA 和 Hibernate 时,PostgreSQL date_trunc('day', (entity.date AT TIME ZONE 'UTC')) 函数的 JPQL 等价物是什么 - What is the JPQL equivalent of the PostgreSQL date_trunc('day', (entity.date AT TIME ZONE 'UTC')) function when using JPA and Hibernate 休眠current_date和date_trunc - Hibernates current_date and date_trunc jpql查询中的date_trunc function - date_trunc function in jpql query JPA 2.1中的@ConstructorResult映射不适用于Hibernate 4.3.5.Final - @ConstructorResult mapping in JPA 2.1 does not work properly with Hibernate 4.3.5.Final databricks 'date_trunc' 函数如何在后端运行? - how does databricks 'date_trunc' function run in the back end? Hibernate JPA 2.1依赖 - Hibernate JPA 2.1 dependency date_trunc org.postgresql.util.PSQLException:错误:“ $ 1”或附近的语法错误 - date_trunc org.postgresql.util.PSQLException: ERROR: syntax error at or near “$1” 将 Hibernate 5.2 迁移到 JPA 2.1 - Migrate Hibernate 5.2 to JPA 2.1 JPA 2.1 和 Hibernate 中的查询缓存 - Query cache in JPA 2.1 and Hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM