1

I am working on a Spring-boot, maven project where I query a MySQL database by the use of hibernate, static metamodels and (org.springframework.data.jpa.domain.)Specification's. My metamodels are autmatically generated by the Hibernate JPA 2 Metamodel Generator. I am using the com.vividsolutions.jts.geom classes for my spatial fields.

I am struggeling for a while now to include those geometry fields in my metamodel since the metamodel generator seems to ignore those. Is there any workaround for this without any major changes? For what I understand, my configuration should work.

A bit more info:

Hibernate dialect: org.hibernate.spatial.dialect.mysql.MySQL5InnoDBSpatialDialect

Pom:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <optional>true</optional>
    <version>5.2.10.Final</version>
</dependency>

Java version 1.8

The annotation processing is handled within my IDE (Eclipse)

In my entities the geometry fields are defined like so

@Column(name="POLYGON", columnDefinition="Geometry")
private Polygon polygon;

Any guidance in the right direction will be greatly appreciated.

Cerebres
  • 343
  • 3
  • 16

2 Answers2

5

With Hibernate 5.3.10, adding the @Basic annotation did the trick, together with adding @Access(AccessType.FIELD) to the class. Without the Access annotation the Geometry type will not appear in the JPA metamodel.

Jaap Reitsma
  • 171
  • 2
  • 7
0

I have the same problem in my project and I worked around it with JPA custom queries.In the query add function - "GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))')" -> https://dev.mysql.com/doc/refman/5.6/en/populating-spatial-columns.html and then it worked.

Angel Botev
  • 96
  • 1
  • 4
  • Hi, welcome to Stack Overflow. While a link to a helpful external resource is always welcome, please also *quote a key excerpt from the page you're linking to*. This is so that if the website goes down or the page is (re)moved, then this answer won't become useless. – Michael Dodd May 02 '17 at 09:00
  • The problem is not that my geometry fields aren't added to my database per se. The problem is that they are not added to my metamodel and thus I cannot query them with the JPA typesafe specification system. – Cerebres May 02 '17 at 10:49