2012-11-19 2 views
1

MySQL 데이터베이스 (v5.5.28)의 항목에 지형 공간 정보 ("Points")를 추가해야합니다. 내가 생각MySQL 엔티티를 EJB 엔티티에 매핑하는 중 오류가 발생했습니다.

Exception [EclipseLink-66] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DescriptorException 
Exception Description: Could not deserialize object from byte array. 
Internal Exception: java.io.StreamCorruptedException: invalid stream header: 00000000 
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[location-->ServiceInfo.location] 
Descriptor: RelationalDescriptor(ies.persistence.entity.ServiceInfo --> [DatabaseTable(ServiceInfo)]) 
at org.eclipse.persistence.exceptions.DescriptorException.notDeserializable(DescriptorException.java:1218) 
at org.eclipse.persistence.mappings.converters.SerializedObjectConverter.convertDataValueToObjectValue(SerializedObjectConverter.java:72) 
... 

:

@Column(name = "location") 
private com.vividsolutions.jts.geom.Point location; 

그러나, 이것은 다음과 같은 오류가 발생합니다 : 나는 간단한 코드를 사용하여 내 자바 EJB 엔티티 서비스 정보 부 (ServiceInfo)의 해당 속성에 생성 된 열 "위치"를 매핑하는 시도 문제는 java mysql 커넥터 (v5.1.22)가 지형 공간 정보를 지원하지 않기 때문에 데이터베이스 이후로 놀라움을 준다. 누군가가 이것이 사실인지 확인할 수 있습니까? 아니면 제가 잘못하고있는 일을 말해 주시고 올바른 방향으로 나를 가리 키시겠습니까?

내가 전환 :

나는 3.1.2

+0

아마도 mysql 커넥터를 넘어선 다른 jar가 필요한 지형 공간 데이터의 매핑을 지원하기 위해서입니다. 이 [토론] (https://groups.google.com/forum/#!topic/play-framework/rz1_asYlzOo)의 세 번째 요점을 살펴보십시오. – remigio

+0

@remigio 덕분에, 나는 내가해야만했던 변화를 완전히 이해하는 데 어려움을 겪었지만, 이것이 올바른 해결책 이었음이 드러났다. – satvheck

답변

0

확인 JDK 1.7과 글래스 피쉬 서버를 사용, 넷빈즈 7.2에서 일하고 있어요, 그래서 결국 내 지속성 계층을 다음과 같이 변경하여 내 문제를 해결 PostGIS 공간 확장을 사용하여 MySQL 데이터베이스에서 PostgeSQL 데이터베이스로. 그 이유는 MySQL이 OpenGIS 사양을 부분적으로 만 구현하기 때문입니다. 다음으로 EclipseLink (JPA 2.0) (기본값)의 지속성 단위를 최대 절전 모드 (JPA 2.0)로 변경해야했습니다.

항아리는 모두 내 프로젝트 글래스 피쉬의 클래스 경로에 포함 (. 그렇지 않으면 찾을 수없는 것 같았다 나는 domain1을의 루트에 복사했다)입니다

  • PostgreSQL을-9.2- 1002.jdbc4.jar
  • PostGIS와-JDBC-2.1.0SVN.jar
  • 최대 절전 모드 4.1.8 (모든 필요한 항아리,는 선택 항목에 대한으로 Ehcache 및 최대 절전 모드 - EntityManager의-4.1.8.Final.jar을 JPA에 대한 .. . 이들은 모두 릴리스 번들에 포함되어 있습니다.)
  • hibernate-spatial-4.0-M1.jar (hibernate-spatial-1.1 .1.jar와 hibernate-spatial-postgis-1.1.1.jar은 Hibernate 4.x와 호환되지 않는다.
  • JTS-1.8.jar

결과 persistence.xml 파일은 다음과 같습니다

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
    <persistence-unit name="IES-ejbPU" transaction-type="JTA"> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 
    <jta-data-source>jdbc/postgresql_iesdb3</jta-data-source> 
    <class>ies.persistence.entity.ServiceInfo</class> 
    <exclude-unlisted-classes>true</exclude-unlisted-classes> 
    <properties> 
     <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/> 
     <property name="hibernate.hbm2ddl.auto" value="update"/> 
    </properties> 
    </persistence-unit> 
</persistence> 

주석은 내 EJB의 실재물에 사용은 다음과 같습니다

@Type(type="org.hibernate.spatial.GeometryType") 
@Column(name = "location", columnDefinition="Geometry") 
private com.vividsolutions.jts.geom.Geometry location; 

우리는 지금이 Hibernate + JPA + PostgeSQL/PostGIS를 이용한 적절한 매핑.

관련 문제