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)
return stammdatenList;}

But I got the error:

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

My Entity looks like:

@Table(name = "partner_stammdaten")
@XmlRootElement(name = "stammdaten")
@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";

    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String name;
    private String strasse;
    private String hausnummer;
    private String ort;
    private String plz;
    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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.