[
https://issues.redhat.com/browse/TEIIDSB-227?page=com.atlassian.jira.plug...
]
Fabian Knoll commented on TEIIDSB-227:
--------------------------------------
This is an example for the workaround. The geom attribute must be of type Clob, not
String:
{code:java}
package com.example.teidvdbless.teidvdblessapp;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.MultiLineString;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.teiid.spring.annotations.SelectQuery;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import java.io.IOException;
import java.sql.Clob;
import java.sql.SQLException;
@Entity
@SelectQuery("SELECT gid, ST_AsText(geom), name FROM nyc.nyc_streets")
public class Street {
@Id
int gid;
@Column
@Lob
Clob geom;
@Column
String name;
public MultiLineString getMultiLineString() throws ParseException, SQLException,
IOException {
String wktString = getWktFromClob(this.geom);
WKTReader wktReader = new WKTReader();
Geometry geometry = wktReader.read(wktString);
return (MultiLineString) geometry;
}
private String getWktFromClob(Clob clob) throws SQLException, IOException {
int lengthInt = calculateLengthOfClob(clob);
char[] chars = new char[lengthInt];
this.geom.getCharacterStream().read(chars);
String wktString = String.copyValueOf(chars);
return wktString;
}
private int calculateLengthOfClob(Clob clob) throws SQLException {
long length = clob.length();
int lengthInt = Math.toIntExact(length);
return lengthInt;
}
}
{code}
Information about support for Hibernate-Spatial
-----------------------------------------------
Key: TEIIDSB-227
URL:
https://issues.redhat.com/browse/TEIIDSB-227
Project: Teiid Spring Boot
Issue Type: Task
Components: datasource
Affects Versions: 1.6.0
Reporter: Fabian Knoll
Priority: Major
Labels: hibernate, spatial, types
Fix For: 1.7.0
Hi,
in our project we tried to use Teiid-Spring-Boot to connect to a PostGIS database. We
want to use the so called [VDB-less
Development|https://github.com/teiid/teiid-spring-boot/blob/master/docs/U...].
Therefore the hibernate spatial mapping for geometry-Types is needed. We tried different
(datasource) configurations, but we couldn't get a running example.
Is the hibernate-spatial type mapping supported in Teiid-Spring-Boot and if so, can you
provide us an example?
Hint: In our entities we use org.locationtech.jts.geom.Geometry (and subtypes) for the
mapped fields.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)