org.hibernate.engine.jdbc.spi.SqlExceptionHelper

在这里,我试图找到所有在我提供的范围内的实体。我的意思是,如果我给出一个特定半径的圆,它必须显示所有实体的位置坐标位于给定的圆内。


我正在使用休眠空间来实现这一点。但是在JPA存储库接口中获得提到的错误。


这是 ,pom.xml


<dependency>

    <groupId>org.hibernate</groupId>

    <artifactId>hibernate-entitymanager</artifactId>

</dependency>

<dependency>

    <groupId>org.hibernate</groupId>

    <artifactId>hibernate-spatial</artifactId>

    <version>5.2.12.Final</version>

</dependency>

<dependency>

    <groupId>org.opengeo</groupId>

    <artifactId>geodb</artifactId>

    <version>${project.version}</version>

</dependency>

<dependency>

    <groupId>mysql</groupId>

    <artifactId>mysql-connector-java</artifactId>

    <version>6.0.6</version>

</dependency>

Jpa Repository,


public interface ResourceRepository extends ExtendedJpaRepository<Resource, String> {   

    @Query(value = "select resource from Resource resource where within(resource.address.location, :circle) = true")

    List<Resource> test(@Param("circle") Geometry circle);

}

Resource.java,


@Entity

@NoArgsConstructor

public class Resource extends UUIDEntity2 implements IsResource {


    @Type(type = "org.hibernate.spatial.GeometryType")

    @OneToOne

    private Address address;


    /*getters setters*/

}

Address.java,


@Entity

public class Address extends UUIDEntity2 implements HasEmailAddress, HasLocation {


    @Embedded

    @Column(columnDefinition = "point")

    private Location location;

    /*getters setters*/

}

location.java,


@Embeddable

@Value(staticConstructor = "of")

@RequiredArgsConstructor(staticName = "of")

public class Location implements Serializable {


    @Column(nullable = true)

    private Double lat;


    @Column(nullable = true)

    private Double lon;

}

测试


    @Inject

    private ResourceRepository resourceRepository;


    public Geometry createCircle(double x, double y, double radius) {

        GeometricShapeFactory shapeFactory = new GeometricShapeFactory();

        shapeFactory.setNumPoints(32);

        shapeFactory.setCentre(new Coordinate(x, y));

        shapeFactory.setSize(radius * 2);

        return shapeFactory.createCircle();

    }


ibeautiful
浏览 515回答 1
1回答

森栏

听起来你没有配置MySQL。您能验证您是否有该行吗?SpatialDialecthibernate.dialect=org.hibernate.spatial.dialect.mysql.MySQL56SpatialDialect在文件中。hibernate.properties您还可以检查日志,了解Hibernate实际使用的方言。它的名称中应包含“空间”,以便空间函数可用于休眠。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java