- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在处理 Spring Boot 项目,我疯狂地尝试正确映射 点 MySql DB 的字段(它是 MariaDB,但它是一样的......)。
要检索我正在使用的数据 Spring Data JPA 在 hibernate 5 .
我的数据库上有这个住宿表:
Field Type Null Key Default Extra
id bigint(20) unsigned NO PRI NULL auto_increment
user_id bigint(20) unsigned NO MUL NULL
accomodation_name varchar(255) NO NULL
description text NO NULL
nation varchar(255) NO NULL
region varchar(255) NO NULL
province varchar(255) NO NULL
city varchar(255) NO NULL
geographical_position point NO NULL
stars int(10) NO NULL
accomodation_typological_id bigint(20) unsigned YES NULL
accomodation_service_id bigint(20) unsigned YES NULL
phone varchar(255) YES NULL
mobile varchar(255) YES NULL
fax varchar(255) YES NULL
email varchar(255) YES NULL
time_stamp datetime YES NULL
import com.vividsolutions.jts.geom.Point;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;
/**
* Created by Yngve on 30/09/16.
*/
@Entity
@Table(name = "accomodation")
public class Accomodation implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
/*@ManyToOne
private Users users;
*/
@OneToMany(mappedBy = "accomodation")
private List<Room> rooms;
@Column(name = "accomodation_name")
private String name;
@Column(name = "description")
@Type(type="text")
private String description;
private String phone;
private String mobile;
private String fax;
private String email;
private Integer stars;
@Column(name = "geographical_position", columnDefinition="Point")
private Point location;
public Accomodation(){
}
// GETTER AND SETTER METHODS
}
@Column(name = "geographical_position", columnDefinition="Point")
private Point location;
import com.vividsolutions.jts.geom.Point;
@Repository
@Transactional(propagation = Propagation.MANDATORY)
public interface AccomodationDAO extends JpaRepository<Accomodation, Long> {
//@Query("FROM Accomodation WHERE id = :id")
Accomodation findById(@Param("id") Long id);
}
@Test
public void placeSearcherControllerTest() {
System.out.println("placeSearcherControllerTest START");
Accomodation accomodation = accomodationDAO.findById(6L);
System.out.println("placeSearcherControllerTest END");
}
Hibernate: select accomodati0_.id as id1_0_, accomodati0_.description as descript2_0_, accomodati0_.email as email3_0_, accomodati0_.fax as fax4_0_, accomodati0_.geographical_position as geograph5_0_, accomodati0_.mobile as mobile6_0_, accomodati0_.accomodation_name as accomoda7_0_, accomodati0_.phone as phone8_0_, accomodati0_.stars as stars9_0_ from accomodation accomodati0_ where accomodati0_.id=?
org.springframework.orm.jpa.JpaSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:333)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:491)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy112.findById(Unknown Source)
at com.betriuvis.controller.test.PlaceSearcherControllerTest.placeSearcherControllerTest(PlaceSearcherControllerTest.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
Caused by: org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:243)
at org.hibernate.internal.util.SerializationHelper.deserialize(SerializationHelper.java:287)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:138)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:113)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:27)
at org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$2.doExtract(VarbinaryTypeDescriptor.java:60)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:234)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:224)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:300)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2738)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1729)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1655)
at org.hibernate.loader.Loader.getRow(Loader.java:1544)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:727)
at org.hibernate.loader.Loader.processResultSet(Loader.java:972)
at org.hibernate.loader.Loader.doQuery(Loader.java:930)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
at org.hibernate.loader.Loader.doList(Loader.java:2617)
at org.hibernate.loader.Loader.doList(Loader.java:2600)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429)
at org.hibernate.loader.Loader.list(Loader.java:2424)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1326)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606)
at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:529)
at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getSingleResult(CriteriaQueryTypeQueryAdapter.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:372)
at com.sun.proxy.$Proxy119.getSingleResult(Unknown Source)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:210)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:82)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:114)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:104)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 36 more
Caused by: java.io.StreamCorruptedException: invalid stream header: 00000000
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:806)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299)
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:309)
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:299)
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:218)
... 86 more
@Column(name = "geographical_position", columnDefinition="Point")
private Point location;
select accomodati0_.id as id1_0_, accomodati0_.description as descript2_0_, accomodati0_.email as email3_0_, accomodati0_.fax as fax4_0_, accomodati0_.geographical_position as geograph5_0_, accomodati0_.mobile as mobile6_0_, accomodati0_.accomodation_name as accomoda7_0_, accomodati0_.phone as phone8_0_, accomodati0_.stars as stars9_0_ from accomodation accomodati0_ where accomodati0_.id=6
select id, AsText(geographical_position) from accomodation where id = 6
id AsText(geographical_position)
--------------------------------------
6 POINT(41.729086 12.278478)
#No auth protected
endpoints.shutdown.sensitive=true
#Enable shutdown endpoint
endpoints.shutdown.enabled=true
logging.file=BeTriviusController.log
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
# Thymeleaf
spring.thymeleaf.cache:false
# DATABASE CONFIG ----------------------------------------------------------------------------------------------------
spring.datasource.url = jdbc:mysql://localhost:3306/betriviustest
spring.datasource.username = root
spring.datasource.password =
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update, validate)
spring.jpa.hibernate.ddl-auto = validate
#spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>BeTriviusController</groupId>
<artifactId>BeTriviusController</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<springboot.version>1.4.1.RELEASE</springboot.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.0.1.Final</version>
<!--<version>4.0</version>-->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
最佳答案
我遇到了完全相同的问题,并且能够提出解决方案。因为,正如您最初指出的 mysql 函数 ST_ASTEXT(column_name)
工作完美,这意味着数据肯定存储正确。
我接受了这一认识,并决定在此基础上构建解决方案。这是我的片段 @Entity
现在。
@Entity
@Table(name = "formEntryData")
public class FormEntryData {
...
@Formula("ST_ASTEXT(data_geo)")
private String dataGeo;
public Geometry getDataGeo() {
try {
WKTReader reader = new WKTReader();
return reader.read(dataGeo);
} catch (ParseException ex) {
return null;
}
}
}
ObjectMapper
使
com.vividsolutions.jts.geom.*
(即
Geometry
、
Point
等)可以序列化为 JSON。
<dependency>
<groupId>com.bedatadriven</groupId>
<artifactId>jackson-datatype-jts</artifactId>
<version>2.3</version>
</dependency>
@Configuration
public class JacksonConfig {
@Bean
public JtsModule jtsModule() {
return new JtsModule();
}
}
关于spring - 为什么我无法使用 Hibernate 5\Spring Data JPA 将数据类型为 "point"的数据库字段检索到这个 Spring Boot 项目中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40301254/
为什么这不返回每个社区(边界框)中的点数? import geopandas as gpd def radius(points_neighbour, points_center, new_field_
嘿! 我有一张图片,我想在该图片上选择一个点并告诉它应该变换到哪个坐标。我想为一些数字点做这个。当我完成时,整个图像会发生变化,因此会考虑局部性。 最重要的是,我可以选择任意多的点,并且所选的点会转换
我有代码: class Point3D{ protected: float x; float y; float z; public:
我正在开发我的第一个 Spring Boot + Spring Data JPA + Hibernate 5,在 PostgreSQL 上工作数据库。 我在尝试映射具有 point 作为数据类型的字段
当我尝试编译这个简单的代码时,我在构造函数中遇到了两个错误:“类型值不能用作默认参数”我该如何解决这个问题? public class PointerArgs { public P
当我尝试编译这个简单的代码时,我在构造函数中遇到了两个错误:“类型值不能用作默认参数”我该如何解决这个问题? public class PointerArgs { public P
目前我正在实现一项提供集体旅行的交通服务,但我遇到了一个问题: 假设我在下图中得到了点 G = {A,B,C,D,F,R,W} =>。 当用户选择 from(A) -> to(W) 时,它们之间有点:
我有一个名为 Shop 的实体,它有一个名为 Position 的 DBGeorgpraphy 列 数据库中的示例商店的位置值为 POINT (145.034242 -37.825519) 我正在尝试
我看了几个类似的帖子,但我要么不明白他们提供的是什么,要么他们似乎不适用。我是新来的,我会尽力遵守规则。 我们在类(class)的最后 2 周学习 c++,期末学习 40 小时 :),所以我是初学者。
我正在使用 tf2 将点从源帧转换为目标帧。下面是代码片段: import tf2_ros import tf2_geometry_msgs transform = tf_buffer.lookup_
我需要找到一种算法,根据给定的一组大小为 n 的点 S 计算凸包。我知道 S 正好有 6 个点 构成了凸包。 最好和最有效的方法是什么? 我想从 S 生成所有可能的点组合(这将是 n 选择 6 个点)
我有一个在屏幕坐标中的 CGPoint。我还有一个应用了变换矩阵(缩放、旋转和平移)的 CALayer。 如何将屏幕坐标中的点转换为图层的局部坐标? 最佳答案 CALayer 有执行此操作的方法,请在
我正在创建自定义控件,它将从点列表(或数组)中绘制形状。我已经完成了基本的绘图功能,但现在我正在为 Visual Studio 中的设计时支持而苦苦挣扎。 我创建了两个属性: private Poin
此函数是从“JavaScript:权威指南”复制的,但由于某种原因它不起作用... **points.dist = function () { ^ ReferenceError: 点未定义**我对此很
我有一个像这样的自定义适配器: private List items = new ArrayList<>(); private Context context; public UserSpinnerA
代码: UPDATE tbl_name SET points = points + 1 WHERE 'GAME 1' LIKE "%Vikes%" GAME 1 列包含包含 Vikes
我有一个点。我正在尝试将 x 作为 int。如果我使用 Point.x,我将得到 x 作为 int。但我的印象是我应该尽可能使用 setter/getter ( Why use getters and
我正在开发一个小型信誉系统,但遇到了一个问题。 因此,在我的示例中,我想为 4 种不同类型的用户创建一个图片网站;我们称他们为:业余、好、非常好、专业。 每个用户可以上传一张图片,这张图片可以被其他用
我有一个关于事件形状模型的问题。我正在使用 T. Coots 的论文(可以找到 here 。) 我已经完成了所有初始步骤(Procrustes 分析计算平均形状,PCA 减少尺寸)但仍停留在拟合上。
Android moving Image one point (0,0) to another point (30,400). using animation or normal looping co
我是一名优秀的程序员,十分优秀!