-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to create partial indexes with Hibernate
PostPosted: Sat Jul 30, 2016 7:03 pm 
Newbie

Joined: Sat Jul 30, 2016 6:55 pm
Posts: 3
How do I specify a partial index using Hibernate / JPA annotations? E.g. an index with a "where" constraint:

Code:
create unique index ix_primary_email_address on contact_email_address (
    contact_id,
    is_primary
)
where is_primary = true;

As you can see, this is necessary to express a constraint whereby only a single entry in a table can have a particular boolean flag set to true.

If this is not possible using regular JPA annotations, how can I instruct Hibernate to run custom SQL at table-creation time? I can find documentation on running custom SQL for queries, but nothing for the actual schema generation.


Top
 Profile  
 
 Post subject: Re: Creating partial indexes
PostPosted: Sun Jul 31, 2016 1:59 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You don't have this possibility. That's why you should use FlywayDB and define incremental migration scripts instead of the HBM2DDL tool which is not meant for production systems.


Top
 Profile  
 
 Post subject: Re: How to create partial indexes with Hibernate
PostPosted: Sun Jul 31, 2016 11:09 am 
Newbie

Joined: Sat Jul 30, 2016 6:55 pm
Posts: 3
Thanks, but how is this possible if you want to use Envers? The documentation says to use hibernate.hbm2ddl.auto to generate the Envers tables: http://docs.jboss.org/hibernate/orm/5.2 ... tml#envers

It also mentions an alternative of using EnversSchemaGenerator, but this class does not exist anymore.

Is the idea to use HBM2DDL in development, then export the schema, and then run that using FlywayDB or Dropwizard?


Top
 Profile  
 
 Post subject: Re: How to create partial indexes with Hibernate
PostPosted: Sun Jul 31, 2016 1:37 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The last sentence is exactly what you should be doing. You can use the HBMDDL initially to generate the first DDL script, and then you can use incremental migration scripts to update it progressively.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.