0

I'm using mysql and wildly.

I want to look for points in a given polygon. My method looks like:

public Response getGeoJsonByBox( @QueryParam("topLeftX") double topLeftX, @QueryParam("bottomRightX") double bottomRightX, @QueryParam("topLeftY") double topLeftY, @QueryParam("bottomRightY") double bottomRightY) { Envelope viewPort = new Envelope(topLeftX, bottomRightX, topLeftY, bottomRightY); List<Stammdaten> stammdatenList = em.createQuery("select s from Stammdaten s where contains(:viewPort, s.coordinate) = true") .setParameter("viewPort", viewPort) .getResultList(); return stammdatenList;} 

But I got the error:

Caused by: java.sql.SQLException: Geometry byte string must be little endian. 

My Entity looks like:

@Entity @Table(name = "partner_stammdaten") @XmlRootElement(name = "stammdaten") @XmlAccessorType(XmlAccessType.FIELD) @NamedQuery(name = Stammdaten.all, query = "SELECT s from Stammdaten s") public class Stammdaten extends GeoJson { public static final String all = "all"; public static final String viewPort = "getByViewPort"; @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; @XmlElement private String name; @XmlElement private String strasse; @XmlElement private String hausnummer; @XmlElement private String ort; @XmlElement private String plz; @XmlElement private int rating; private double longtitude; private double latitude; private Point coordinate; private int placeId; private String osmId; public Stammdaten() { } //Getters/Setters and other implementation } 

So by the documentation of hibernate spatial the contains method is available for mysql. And both of the objects passed to my method are a type of geometry.

So I haven't any idea why this error happens.

Any idea on this would be nice.

2
  • See MySQL string encoding for Geometry package Commented Apr 9, 2017 at 15:38
  • I tried to convert the Charset. I can't make a geometry column to utf16le. And if I change the column to mediumtext and utf16le I can't save things there. Commented Apr 10, 2017 at 7:46

1 Answer 1

0

Asking a Friend of mine, to have a look at the code brings the answer.

I didn't recognized, that Envelope isn't a Geometry. All other classes seems to extend Geometry but Envelope didn't. So the query did not get a geometry type to compare with a geometry.

Building a Polygon from my Envelope and put this into the query did the trick.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.