5

How do I properly annotate a PostgreSQL GIN index with Hibernate?

@Index(...)
String text;

Does hibernate create a GIN index by default, or do I have to set a special property somewhere?

user1432882
  • 1,126
  • 4
  • 14
  • 29

1 Answers1

3

Looks like you can't create custom indexes directly with Hibernate's annotations. See related: How to use Hibernate Annotations to add an index on a Lob / Clob / tinyblob, where an answer mentions how to do it with auxillary objects.

In your situation I would query the system catalogs (information_schema or pg_catalog) for the index at startup and, if it wasn't found, execute CREATE INDEX statement with native SQL.

See this answer to a very similar question about creating triggers in Hibernate.

Community
  • 1
  • 1
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778