0

My code is very similar to that shown in this question: Hibernate custom schema creation

Although the code is the same, my specific question is different:

How can I force Hibernate to generate additional custom indexes? For instance, PostgreSQL partial indexes which cannot be expressed in annotations?

What I have tried so far:

  • Searched google
  • Searched SO
  • Read the documentation
  • Check the Javadocs

The primary reason for not wanting to manually maintain the indexes, is the use of CI/CD with throwaway databases which get rebuilt every time a new environment is initialized.

Alex R
  • 11,364
  • 15
  • 100
  • 180

1 Answers1

0

Because you need to use postgresql specific code (of which hibernate is not aware) you will have to create the indexes outside of hibernate.
What you can do is to write the index statements (you probably know the exact names of the tables/columns that you want to index) in an .sql file and run it right after hibernate finishes with the creation of the database. The easiest way to do this is by putting that file on the classpath and naming it import.sql. You can find more info on that here.

Anyway I would strongly suggest using some kind of a database version control manager (flyway, for example) instead of relaying on hibernate to generate the tables.

Dimitar Spasovski
  • 2,023
  • 9
  • 29
  • 45