I am trying to deserialize a point into a java object.
Here is the entity class I am using.
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import com.vividsolutions.jts.geom.*;
@Data
@Entity(name = "magic_points")
public class MagicPoint {
@Id
Integer id;
@Column(name = "p", columnDefinition="Point")
private Point point;
@Column(name = "description")
private String description;
}
The repository
import com.playground.springplayground.db.entities.MagicPoint;
import com.vividsolutions.jts.geom.Point;
import org.springframework.data.repository.Repository;
public interface MagicPointRepository extends Repository<MagicPoint, Integer> {
List<MagicPoint> getAllByDescription(String description);
}
And the way how I am calling it.
List<MagicPoint> magicPoints = magicPointRepository.getAllByDescription("Abc");
I am using the following library for geodata:
compile group: 'com.vividsolutions', name: 'jts', version: '1.13'
Database is a MySql, Ver 8.0.13
And the data I stored in Database:
This is the error I am receiving:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize] with root cause
java.io.StreamCorruptedException: invalid stream header: E6100000
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:866) ~[na:1.8.0_181]
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:358) ~[na:1.8.0_181]
Is com.vividsolutions.jts is a good approach for mapping geodata stored in SQL databases? Is it something I am missing? I couldn't find anything related to this until now. The mapping error message doesn't bring any useful information if there is a driver missing or some other dependency I should consider.
EDIT In order to reproduce it on your local machine I added the code on Github
git clone https://github.com/florin-t/deserialize-geolocation-point.git
There is also a README.TXT with some instructions regarding the Database and application.config.
set the mysql dialect to org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect
eg. spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect
also make sure you do not have incompatibilities with the hibernate library (if you use hibernate-spatial 5.2.5.Final you project works)