Skip to main content

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

My German is not so good,  Google translate gives,

"The SQL for an instance of org.postgis.Point to use data type can not be
derived. Use 'setObject ()' set an explicit type for him."

for your error, could you translate this better?

What does JDBC return when selecting the Point type using getObject()? and
how does it require it to be set?  The error seems to indicate we are using
setObject(), but it does not like this?

EclipseLink has support for spatial datatypes on Oracle, using its JGeometry
converter.  Oracle returns spatial data a Struct datatypes, is PostgreSQL
similar?



Philipp123451 wrote:
> 
> 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 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://old.nabble.com/eclipseLink-%2B-PostGIS-datatypes-tp27026862p27026880.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top