J'utilise Spring boot avec Hibernate pour une requête spatiale. Bibliothèques utilisées: 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
Chaque fois que j'utilise HQL comme illustré ci-dessous dans Query, j'obtiens l'erreur suivante lors du démarrage de l'application, mais lorsque j'essaie d'utiliser une requête native, cela fonctionne.
J'ai essayé avec différents dialectes. Aussi, essayé d'utiliser columnDefinition avec la valeur comme géométrie, 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);
}
Actuellement, j'obtiens l'erreur suivante au démarrage:
Provoqué par: org.hibernate.hql.internal.ast.QuerySyntaxException: nœud AST inattendu: (près de la ligne 1, colonne 164 [sélectionnez le maître dans com.orange.alc.polygon.dao.entity.PolygonMasterEntity maître OERE dans (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
1 réponse
Vous avez and
juste derrière WHERE
dans votre requête. Je ne pense pas que ce soit du HQL légitime et vous devriez laisser tomber le and
.
De nouvelles questions
spring
Le Spring Framework est un framework open source pour le développement d'applications sur la plate-forme Java. Son cœur est un support riche pour les architectures basées sur les composants, et il compte actuellement plus de vingt modules hautement intégrés.