我正在使用主题中所述的框架.
这是我在application.yml for spring中的jpa属性的一部分
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
我不确定这是否是触发SpatialDialect for MySQL5.7的正确方法
我的实体的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;
}
我创建了一个类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);
}
}
使用@Type(type =“com.iheartcity.apiapp.geometry.MySQLGeometryType”)
它完美地运作.但是,当我评论它时,我在运行代码以检索数据时开始出错.
这是一个例外:
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]
最佳答案 实际的解决方案是删除@Type并使用@Column(name =“location”,nullable = false,columnDefinition =“Point”)
请注意,这是针对MySQL的