Note that there are some explanatory texts on larger screens.

plurals
  1. POSpecifying index method when using @Index annotation
    text
    copied!<p>I'm using (spatial) hibernate annotations to create a schema for a spatial application that is implemented on top of PostGIS. When creating the database schema from my annotated classes, I'm in need to create spatial indexes for speeding up spatial queries that are used throughout the application. </p> <pre class="lang-java prettyprint-override"><code>@Entity @Table(name = "MY_CLASS") @org.hibernate.annotations.Table( appliesTo = "MY_CLASS", indexes = { @Index(name = "idx_my_class_sidx", columnNames = { "GEOM" }) }) public class MyClass { [...] @Column(name = "GEOM") @Type(type = "org.hibernate.spatial.GeometryType") private LineString geom; [...] } </code></pre> <p>While the exported schema contains the index, unfortunately it has been created with an undesired index method; hibernate seems to default to <code>btree</code> however PostGIS recommends the use of <code>GIST</code> indexes when dealing with spatial data (see <a href="http://postgis.net/docs/manual-2.0/using_postgis_dbmanagement.html#id441511" rel="nofollow">http://postgis.net/docs/manual-2.0/using_postgis_dbmanagement.html#id441511</a>).</p> <pre class="lang-sql prettyprint-override"><code>CREATE INDEX idx_my_class_sidx ON my_class USING btree (geom); </code></pre> <p>Whereas I might just fall back creating the index with plain SQL, I'm wondering if there is a way to use hibernate annotations to override the default method type for PostgreSQL? Solutions or even ideas how to do that would be highly appreciated.</p> <p>TIA, Tilman</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload