I'm using the frameworks as stated in the topic.
this is my part of my jpa properties in application.yml for spring
jpa:
database: mysql
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
properties:
hibernate:
dialect: org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect
globally_quoted_identifiers: true
show-sql: true
I'm not sure if this is the right way to trigger SpatialDialect for MySQL5.7
My entity's method for Point
@Type(type = "com.iheartcity.apiapp.geometry.MySQLGeometryType")
@Column(name = "location", nullable = false)
public Point getLocation() {
return this.location;
}
public void setLocation(Point location) {
this.location = location;
}
I created a class MySQLGeometryType.java:
package com.iheartcity.apiapp.geometry;
import org.hibernate.spatial.JTSGeometryType;
import org.hibernate.spatial.dialect.mysql.MySQLGeometryTypeDescriptor;
public class MySQLGeometryType extends JTSGeometryType {
public MySQLGeometryType() {
super(MySQLGeometryTypeDescriptor.INSTANCE);
}
}
With the @Type(type = "com.iheartcity.apiapp.geometry.MySQLGeometryType")
it works perfectly. However, when I commented it, I start to get error when running the code to retrieve the data.
Here is the exception:
java.io.StreamCorruptedException: invalid stream header: 00000000
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:808) ~[na:1.8.0_111]
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:301) ~[na:1.8.0_111]
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:309) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:299) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:218) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.util.SerializationHelper.deserialize(SerializationHelper.java:287) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:139) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:114) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:28) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$2.doExtract(VarbinaryTypeDescriptor.java:60) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:258) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:244) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:327) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2775) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1741) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1667) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.getRow(Loader.java:1556) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:740) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.processResultSet(Loader.java:985) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:943) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2615) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2598) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2430) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.Loader.list(Loader.java:2425) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1458) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1426) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1398) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]
at org.hibernate.Query.getResultList(Query.java:417) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final]at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:808) ~[na:1.8.0_111]
The actual solution is to remove @Type
and use @Column(name = "location", nullable = false, columnDefinition = "Point")
Note that this is for MySQL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With