我正在使用主题中所述的框架.这是我在application.yml for spring中的jpa属性的一部分jpa:database: mysqlhibernate:naming:physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardIm...
我正在使用主题中所述的框架.
这是我在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的
本文标题为:java – Hibernate-Spatial,JPA,Spring,MySQL 5.7(无法检索Point)
基础教程推荐
- Java Graphics实现界面显示文字并换行 2023-04-23
- 基于javaweb+jsp实现学生宿舍管理系统 2023-07-30
- EJB3.0部署消息驱动Bean抛javax.naming.NameNotFoundException异常 2023-07-30
- Java OpenCV图像处理之图形与文字绘制 2022-11-01
- 详解如何在项目中应用SpringSecurity权限控制 2023-02-04
- Java编译错误信息提示java.lang.ExceptionInInitializer解决 2023-03-11
- 可视化定时任务quartz集成解析全过程 2023-06-17
- java开源好用的简繁转换类库推荐 2023-04-12
- 一文带你深入剖析Java线程池的前世今生 2023-06-17
- 一文了解Java中枚举的使用 2023-05-13