I'm trying to setup a new project with the following combination of technologies
Entity. I found that org.hibernate.spatial.GeometryType
has been removed, and now appears to be moved to org.geolatte.geom.GeometryType
in geo-latte-1.0.jar
@Entity
@Table(name = "AREA")
@NamedQueries(@NamedQuery(name = "findAllAreas", query = "SELECT t FROM Area t"))
public class Area {
private long id;
private String info;
private Geometry location;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "INFO")
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
@Column(name = "POLYGON")
@Type(type = "org.geolatte.geom.GeometryType")
public Geometry getLocation() {
return location;
}
public void setLocation(Geometry location) {
this.location = location;
}
}
Spring setup
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<array>
<value>org.example.entity</value>
</array>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect
</prop>
</props>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/sadb" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
Database setup
Result
Am am able to persist and retrieve Area entities without issues. However the type on the column seems is byte data, not a PostGIS spatial type.. Any ideas what am I doing wrong?
sadb=> \d+ area;
Table "public.area"
Column | Type | Modifiers | Storage | Stats target | Description
---------+------------------------+-----------+----------+--------------+------------
id | bigint | not null | plain | |
info | character varying(255) | | extended | |
polygon | bytea | | extended | |
With Hibernate 5+ you don't need the @Type annotation. Including it seems to cause the error I was seeing. Removing it fixes the issue. The polygon column how has a PostGIS type of geometry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With