Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] eclipseLink + PostGIS datatypes

Hello everybody.
As the topic indicates, I'm trying to use JPA
(eclipselink-2.0.0.v20091127-r5931) with glassfish v3 and PostGres 8.4 with
PostGIS 1.4.1. The Problem is, PostGIS datatypes (e.g. org.postgis.Point) is
converted to type "bytea" during the persistence process. I've found several
blogs saying this should be possible, but for me this seems impossible. For
example:
http://www.naxos-software.de/blog/index.php?/archives/40-PostgreSQLs-geometrische-Datentypen-und-die-Java-Persistence-API.html
. At the bottom of this article someone says, this:
@Entity @Table(name = "route_point") public class RoutePoint implements
Serializable { @Id @GeneratedValue @Column(name = "id", nullable = false)
private Integer id;

@Column(name = "seq_no", nullable = false)
private int seqNo;
@JoinColumn(name = "route", referencedColumName = "id")
@ManyToOne
private Route route;
@Column(name = "geo_point", nullable = false)
@Lob
@Convert
private Geometry pointAsObject;

public RoutePoint() {
}

}

shall be working. I tried but was not successfull. eclipselink returns:

Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: FEHLER: Spalte »test«
hat Typ point, aber der Ausdruck hat Typ bytea
Error Code: 0
Call: INSERT INTO test (id, test) VALUES (?, ?)
        bind => [601, [B@552da4]
Query: InsertObjectQuery(entity.Test[id=601])

Another way I tried is to implement the "Converter" interface of
eclipseLink. I added to the attribute of type point the following:

@Converter(name="convert", converterClass=MyTypeConverter.class)
public class Test implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column(name = "test")
    @Convert("convert")
    private Point test;

    @Id
    @Basic(optional = false)
    @Column(name = "id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer id;
...
}

The implementation of the Converter looks like that:

public class MyTypeConverter implements Converter{
    public Point convertObjectValueToDataValue(Object objectValue, Session
session) {
        return (Point) objectValue;
    }

    public Point convertDataValueToObjectValue(Object dataValue, Session
session) {
        return (Point)dataValue;
    }

    public boolean isMutable() {
        return false;
    }

    public void initialize(DatabaseMapping mapping, Session session) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }
}

eclipseLink now returns:

Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: Der in SQL für eine
Instanz von org.postgis.Point zu verwendende Datentyp kann nicht abgeleitet
werden. Benutzen Sie 'setObject()' mit einem expliziten Typ, um ihn
festzulegen.
Error Code: 0
Call: INSERT INTO test (id, test) VALUES (?, ?)
        bind => [601, POINT(0 0)]
Query: InsertObjectQuery(entity.Test[id=601])

I don't see the failure. I would be very pleased if someone could tell me
how to solve this problem.

With regards
Philipp 
-- 
View this message in context: http://old.nabble.com/eclipseLink-%2B-PostGIS-datatypes-tp27026862p27026862.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top