在Hibernate Spatial中使用HQL时无法获取查询

我正在将Spring boot和Hibernate一起用于空间查询。 使用的库: 1. Spring Boot-2.1.3.RELEASE 2.休眠空间-5.3.7.Final 3. MariaDB-MySQL Ver 15.1发行版10.1.36-MariaDB

每当我按以下查询中所述使用HQL时,在应用程序启动期间都会出现以下错误,但是当我尝试使用本机查询时,它将起作用。

我尝试使用不同的方言。另外,尝试将columnDefinition的值用作几何图形,geolatte-geometry。

pom.xml

<int:section>

application.yml

<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>

当前,我在启动过程中遇到以下错误:

由以下原因引起:org.hibernate.hql.internal.ast.QuerySyntaxException:意外的AST节点:(在第1行第164列附近[从com.orange.alc.polygon.dao.entity.PolygonmasterEntity主节点中选择主节点, master.geometry,:point)]

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);

}
h975969910 回答:在Hibernate Spatial中使用HQL时无法获取查询

您的查询中and后紧跟WHERE。 我认为这不是合法的HQL,您应该删除and

,

spring.jpa.properties下的属性按原样使用,并作为Map直接传递给JPA。由于Spring(Boot)不会解析这些内容,因此您无法使用常规的YAML语法,而必须像使用.一样包含属性名称。 in this Github issueSpring Boot Documentation也对此进行了说明。

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
  jpa:
    hibernate:
      ddl-auto: none
    properties:
      hibernate.jdbc.lob.non_contextual_creation: true
      hibernate.physical_naming_strategy: com.orange.alc.polygon.dao.config.DefaultNamingStrategy 
      hibernate.format_sql: false
      hibernate.dialect: org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect 

应该工作并设置适当的方言。

本文链接:https://www.f2er.com/3168695.html

大家都在问