gpt4 book ai didi

java - MSSql 服务器 jpa 空间异常

转载 作者:行者123 更新时间:2023-12-04 13:46:48 24 4
gpt4 key购买 nike

是否可以在jpa中使用sql空间数据?我有 MS SQL Server 2014 速成版。我正在尝试按如下方式使用空间数据;

  • maven (pom.xml) 依赖项;
    <dependency>
    <groupId>com.vividsolutions</groupId>
    <artifactId>jts</artifactId>
    <version>1.13</version>
    </dependency>

    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-spatial</artifactId>
    <version>5.2.10.Final</version>
    </dependency>
  • db方言;

  • spring.jpa.hibernate.dialect=org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect
  • 实体定义;

    @Column(columnDefinition = "几何")
    私有(private)点位;
  • 数据的创建;

    SampleEntity se = new SampleEntity();
    se.setName("样本 1");
    se.setAge(30);
    GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
    点 location1 = gf.createPoint(new Coordinate(0, 0, 4384));
    location1.setSRID(4326);
    se.setLocation(location1);
    System.out.println("LOCATION 1 SRID:"+ se.getLocation().getSRID());
    System.out.println("几何网格:"+ gf.getSRID());
    sampleEntityRepository.save(se);

  • 我得到以下异常;

    "Hibernate: insert into sample_entity (age, author, date_created, date_updated, location, name) 值 (?, ?, ?, ?, ?, ?)

    2017-07-13 16:49:53.655 WARN 6600 --- [main] o.h.engine.jdbc.spi.SqlExceptionHelper:SQL 错误:6522,SQLState:S0001

    2017-07-13 16:49:53.656 ERROR 6600 --- [main] o.h.engine.jdbc.spi.SqlExceptionHelper:在执行用户定义的例程或聚合“地理”期间发生 .NET Framework 错误:

    System.ArgumentException:24204:空间引用标识符 (SRID) 无效。指定的 SRID 必须与 sys.spatial_reference_systems 目录 View 中显示的受支持 SRID 之一匹配。

    System.ArgumentException:

    在 Microsoft.SqlServer.Types.SqlGeography.set_Srid(Int32 值)

    在 Microsoft.SqlServer.Types.SqlGeography.Read(BinaryReader r)

    在 SqlGeography::.DeserializeValidate(IntPtr, Int32, CClrLobContext*)
    .”

    有什么解决办法吗?或者,我做错了什么?

    最佳答案

    您遇到的问题是由于指定了不正确的方言属性:

    spring.jpa.hibernate.dialect


    应该

    spring.jpa.properties.hibernate.dialect


    整个字符串是:“spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect”
    然后,一切都应该正常工作。可以在spring的日志中看到:
    org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect

    关于java - MSSql 服务器 jpa 空间异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45083149/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com