I am using Spring boot along with Hibernate for a Spatial query. Libraries used: 1. Spring boot - 2.1.3.RELEASE 2. Hibernate Spatial - 5.3.7.Final 3. MariaDB - mysql Ver 15.1 Distrib 10.1.36-MariaDB
Whenever I use HQL as depicted below in Query, I am getting the following error during application startup however when I try using native query it works.
I have tried with different dialects. Also, tried using columnDefinition with value as geometry, geolatte-geometry.
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<exclusions>
<exclusion>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
application.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: none
properties:
hibernate:
jdbc:
lob:
non_contextual_creation: true
physical_naming_strategy: com.orange.alc.polygon.dao.config.DefaultNamingStrategy
format_sql: false
dialect: org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect
@Entity
public class PolygonMasterEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// Here we have used Geolatte library
private Polygon geometry;
@Column(name = "is_active")
private Boolean active;
@Column(name = "is_deleted")
private Boolean deleted;
}
@Repository
public interface PolygonMasterRepository extends JpaRepository<PolygonMasterEntity, Long>,
JpaSpecificationExecutor<PolygonMasterEntity> {
@Query("select master from #{#entityName} master WHERE"
+ " and within(master.geometry, :point)")
List<PolygonMasterEntity> findCostUsingPointForLLME(
@Param("point") Point point);
}
Currently, I am getting the following error during startup:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: ( near line 1, column 164 [select master from com.orange.alc.polygon.dao.entity.PolygonMasterEntity master WHERE within(master.geometry, :point)]
~~~~~~~~~ at org.hibernate.hql.internal.ast.ErrorTracker.throwQueryException(ErrorTracker.java:93)
~~~~~~~~~ at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:277)
~~~~~~~~~ at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:191)
~~~~~~~~~ at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:143)
~~~~~~~~~ at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:119)
~~~~~~~~~ at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
~~~~~~~~~ at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
~~~~~~~~~ at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:595)
~~~~~~~~~ at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:704)
~~~~~~~~~ ... 100 common frames omitted
:to delimit properties forspring.jpa.propertiesthey have to use.. The properties are used as is and thus don't support the:. So usehibernate.dialectinstead etc. This applies to all the properties under thespring.jpa.propertiesnamespace. See github.com/spring-projects/spring-boot/issues/17975