Is it possible to use sql spatial data in jpa? I ve MS SQL Server 2014 Express Edition. I m trying to use spatial data as follows;
maven (pom.xml) dependencies;
<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 dialect;
spring.jpa.hibernate.dialect=org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect
entity definition;
@Column(columnDefinition = “Geometry”)
private Point location;creation of data;
SampleEntity se = new SampleEntity();
se.setName(“Sample1”);
se.setAge(30);
GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 4326);
Point 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(“geometry srid: ” + gf.getSRID());
sampleEntityRepository.save(se);
And i get following exception;
“Hibernate: insert into sample_entity (age, author, date_created, date_updated, location, name) values (?, ?, ?, ?, ?, ?)
2017-07-13 16:49:53.655 WARN 6600 — [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 6522, SQLState: S0001
2017-07-13 16:49:53.656 ERROR 6600 — [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : A .NET Framework error occurred during execution of user-defined routine or aggregate “geography”:
System.ArgumentException: 24204: The spatial reference identifier (SRID) is not valid. The specified SRID must match one of the supported SRIDs displayed in the sys.spatial_reference_systems catalog view.
System.ArgumentException:
at Microsoft.SqlServer.Types.SqlGeography.set_Srid(Int32 value)
at Microsoft.SqlServer.Types.SqlGeography.Read(BinaryReader r)
at SqlGeography::.DeserializeValidate(IntPtr , Int32 , CClrLobContext* ) .”
Is there any solution? Or, am i doing sth wrong?
Advertisement
Answer
The problem you have is due to specing incorrect dialect property:
spring.jpa.hibernate.dialect
should be
spring.jpa.properties.hibernate.dialect
And whole string is: “spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect”
Then, all should be working correctly. You can see it in the log of spring:
org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect