|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
PostGIS - hibernate - EJB3Hi,
I am trying to use EJB3 in Java JBoss (which is hibernate behind the scenes), I have marked up a property as follows @Column(name="extents") public Geometry getExtents() { return extents; } And my data source looks like <datasources> <local-tx-datasource> <jndi-name>GeoDataDS</jndi-name> <connection-url>jdbc:postgresql://127.0.0.1:5432/geometa</connection-url > <driver-class>org.postgis.DriverWrapper</driver-class> <user-name>xxx</user-name> <password>xxx</password> <metadata> <type-mapping>PostgreSQL 8.1</type-mapping> </metadata> </local-tx-datasource> </datasources> Where extents is of type org.postgis.Geometry, when I tell the entityManager to commit this I get invalid geometry error even when I commit an empty polygon, or simple linestring such as LineString ls = new LineString("LINESTRING(191232 243118,191108 243242)"); If anyone has done this with EJB3 I would be really grateful for some advice, but if you have done it with hibernate I would also be interested as they are pretty similar. Many thanks, Norman _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users |
|
|
RE: PostGIS - hibernate - EJB3Hi,
I have searched all over the place for this, and no one has posted a solution , just the same question !! - apologies if you have already solved this, hope it helps someone. This allows you to use spatial types from within the EJB3 Java Persistence Architecture. The solution is as follows (only tested in write mode so far); EJB3 annotation (the @Type hibernate annotation is key here) @Type(type = "org.osgeo.geodata.hibernate.GeometryType") @Column(name="extents") public Geometry getExtents() { return extents; } and then GeometryType looks like this package org.osgeo.geodata.hibernate; import java.io.Serializable; import java.sql.Blob; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import org.hibernate.HibernateException; import org.hibernate.usertype.UserType; import org.postgis.Geometry; import org.postgis.binary.BinaryParser; import org.postgis.binary.BinaryWriter; /** * @author nbarker $date 16/8/06 */ public class GeometryType implements UserType { private static final int[] SQL_TYPES = { Types.BLOB }; /** * @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object) */ public Object deepCopy(Object value) throws HibernateException { return value; } /** * @see org.hibernate.usertype.UserType#equals(java.lang.Object, java.lang.Object) */ public boolean equals(Object x, Object y) throws HibernateException { if (x == y) { return true; } else if (x == null || y == null) { return false; } else { return x.equals(y); } } /** * @see org.hibernate.usertype.UserType#hashCode(java.lang.Object) */ public int hashCode(Object arg0) throws HibernateException { // TODO Auto-generated method stub return 0; } /** * @see org.hibernate.usertype.UserType#isMutable() */ public boolean isMutable() { return false; } /**) * @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String[], java.lang.Object) */ public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException { Geometry result = null; Blob geomAsBlob = resultSet.getBlob(names[0]); if (!resultSet.wasNull()) { BinaryParser bp = new BinaryParser(); result = geomAsBlob == null ? null : bp.parse(geomAsBlob.getBytes(1, (int)geomAsBlob.length())); } return result; } /** * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int) */ public void nullSafeSet(PreparedStatement statement, Object value, int index) throws HibernateException, SQLException { if (value == null) { statement.setBytes(index, null); } else { BinaryWriter bw = new BinaryWriter(); byte[] bytes = bw.writeBinary((Geometry)value); statement.setBytes(index, bytes); } } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#replace(java.lang.Object, java.lang.Object, java.lang.Object) */ public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException { // TODO Auto-generated method stub return null; } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#returnedClass() */ public Class returnedClass() { return Geometry.class; } /** * @see org.hibernate.usertype.UserType#sqlTypes() */ public int[] sqlTypes() { return GeometryType.SQL_TYPES; } /** * @see org.hibernate.usertype.UserType#assemble(java.io.Serializable, java.lang.Object) */ public Object assemble(Serializable cached, Object owner) throws HibernateException { return cached; } /** * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object) */ public Serializable disassemble(Object value) throws HibernateException { return (Serializable)value; } } -----Original Message----- From: postgis-users-bounces@... on behalf of Norman Barker Sent: Mon 8/7/2006 4:08 PM To: PostGIS Users Discussion Subject: [postgis-users] PostGIS - hibernate - EJB3 Hi, I am trying to use EJB3 in Java JBoss (which is hibernate behind the scenes), I have marked up a property as follows @Column(name="extents") public Geometry getExtents() { return extents; } And my data source looks like <datasources> <local-tx-datasource> <jndi-name>GeoDataDS</jndi-name> <connection-url>jdbc:postgresql://127.0.0.1:5432/geometa</connection-url > <driver-class>org.postgis.DriverWrapper</driver-class> <user-name>xxx</user-name> <password>xxx</password> <metadata> <type-mapping>PostgreSQL 8.1</type-mapping> </metadata> </local-tx-datasource> </datasources> Where extents is of type org.postgis.Geometry, when I tell the entityManager to commit this I get invalid geometry error even when I commit an empty polygon, or simple linestring such as LineString ls = new LineString("LINESTRING(191232 243118,191108 243242)"); If anyone has done this with EJB3 I would be really grateful for some advice, but if you have done it with hibernate I would also be interested as they are pretty similar. Many thanks, Norman _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users |
|
|
Re: PostGIS - hibernate - EJB3Hi, Norman,
Norman Barker wrote: > I have searched all over the place for this, and no one has posted a > solution , just the same question !! - apologies if you have already > solved this, hope it helps someone. > > This allows you to use spatial types from within the EJB3 Java > Persistence Architecture. > > The solution is as follows (only tested in write mode so far); Looks interesting. Would you like to contribute it under [L]GPL, so we can include it into the PostGIS sources? Thanks, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users |
|
|
|
|
|
Re: PostGIS - hibernate - EJB3Hi, Norman,
Norman Barker wrote: > I am doing this as part of the OSGEO Geodata project - but I agree its > home is in postgis for this part, I wanted to give it as free a license > as possible - does MIT or BSD sound fine to you, or even Apache - I > personally have no problems with LGPL (JBoss has this license), but > other companies do. At least the so-called "revised" BSD License should be fine (the same PostgreSQL uses), but the old BSD License and the Apache License are currently not compatible with the GPL. Note also that someone who has problems with LGPL will not be able to use the org.postgis.* classes you wrap, as those are LGPL, and are unlikely to change to a more liberal license. (The rest of PostGIS is GPL.) > I will package it all up with docs and an ejb deployer and sent it to > you in the near future (within 2 weeks). Thanks a lot! Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users |
|
|
RE: PostGIS - hibernate - EJB3hi, I am trying to use custom UserType, but it work fine in a pure Hibernate implementation , but not in JBOSS EJB3, the generated geometry column in postgres is of type "oid" instead of "geometry" You have any suggestion, i am using jboss-EJB-3.0_RC8-FD and postgis 1.1.3 (on postgres 8.1.4)
thanks. |
|
|
|
|
|
RE: RE: PostGIS - hibernate - EJB3hi,
I have the same problem with JBoss and EJB3. The column is type "oid" instead of "geometry". I would be very grateful for a solution - here are my postgis-ds.xml and my persistence.xml: <datasources> <local-tx-datasource> <jndi-name>PostgisDS</jndi-name> <connection-url>jdbc:postgresql://xxx:5432/tourguide</connection-url> <driver-class>org.postgis.DriverWrapper</driver-class> <user-name>xxx</user-name> <password>xxx</password> <new-connection-sql>select 1</new-connection-sql> <check-valid-connection-sql>select 1</check-valid-connection-sql> <metadata> <type-mapping>PostgreSQL 8.1</type-mapping> </metadata> </local-tx-datasource> </datasources> <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="tourguide"> <jta-data-source>java:/PostgisDS</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="true"/> </properties> </persistence-unit> </persistence> Thanks! Christian.
|
|
|
RE: RE: RE: PostGIS - hibernate - EJB3Hi, _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users |
|
|
RE: RE: RE: PostGIS - hibernate - EJB3Hi Norman,
thank you for your tutorial! Storing data in a geometry column works fine if I create a new object and persist it with the entity manager. But if I try to edit the data with 'merge' from the database manager its not working: PersonEntity pe = entityManager.find(PersonEntity.class, new Long(1).longValue()); pe.setLocation(new Point(8,5)); entityManager.merge(pe); How can I fix this problem? And their is a NullPointerException if I try to read a list of data from the database: public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException { Geometry result = null; String geom = resultSet.getString(names[0]); try{ BinaryParser parser = new BinaryParser(); result = parser.parse(geom); } catch(NullPointerException e){ logger.error("nullSafeGet() geom result"+geom); } return result; } Tank you for your help, Christian.
|
|
|
|
|
|
Re: RE: RE: RE: PostGIS - hibernate - EJB3Hi, Norman,
Norman Barker wrote: > I have asked for commit access to postgis this morning but for now if > you replace the the 'replace' method in > org.postgis.hibernate.GeometryType as follows; > > public Object replace(Object original, Object target, Object > owner) throws HibernateException { > return original; > } > > Then the merge operation will work. I just committed this change to the repository. When I started sending patches to the java code to postgis-devel, strk felt flooded after some time, and asked Paul to give me commit access. That's how I became maintainer :-) Thanks, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in Europe! www.ffii.org www.nosoftwarepatents.org _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users |
|
|
Re: RE: RE: RE: PostGIS - hibernate - EJB3Hi Norman,
thanks for your patch. Sorry for my late response to your mail (nice weather and wonderful mountains here in austria). I have tested it - it works fine now! Thanks, Christian.
|
|
|
RE: RE: RE: PostGIS - hibernate - EJB3Hi Norman (and others),
I have serveral questions/problems: 1. Can you point me where I can find your manual concerning PostGIS and the use of GeometryType ? 2. In the thread here, people are using: <driver-class>org.postgis.DriverWrapper</driver-class> When I do the same, I get a "No suitable driver" exception. For the moment I am using: <driver-class>org.postgresql.Driver</driver-class> and that seems to work for simple tests. Is this important ? Maybe this is related with the errors I am getting further the line. 3. I wanted to use the GeometryType that is packed in PostGIS 1.1.5. After generating the new JAR and replacing the old one by this one, I start getting new exceptions: The class org.postgis.PGbox3d does not implement org.postgresql.util.PGobject. Any Idea what this means ?? 4. Now I put the old PostGIS back and make a very small JAR that contains BinaryWriter and GeometryType, and also add it to the classpath. This is what he sais now: org.hibernate.MappingException: Could not determine type for: org.postgis.hibernate.GeometryType My object looks like this: ........ @Type(type = "org.postgis.hibernate.GeometryType") @Column(name="footprint", columnDefinition="Geometry") public Geometry getFootprint() { return footprint; } public void setFootprint(Geometry footprint) { this.footprint = footprint; } .................... And if I add 'import org.postgis.hibernate.GeometryType' to the object, he does not complain he does not know that import, so the GeometryType is well added to the project. Is there anyone who sees a light through this strange effects ? thanks in advance, Jan
|
|
|
|
|
|
Re: RE: RE: RE: PostGIS - hibernate - EJB3Hi,
Norman Barker wrote: > 2. In the thread here, people are using: > <driver-class>org.postgis.DriverWrapper</driver-class> > When I do the same, I get a "No suitable driver" exception. [...] > 3. I wanted to use the GeometryType that is packed in PostGIS 1.1.5. > After generating the new JAR and replacing the old one by this one, > I start getting new exceptions: > The class org.postgis.PGbox3d does not implement > org.postgresql.util.PGobject. Those 2 things look like a classpath/classloader problem. You have to make sure that the postgis.jar and the postgresql-jdbc.jar are available via the same classloader (and that you don't have two incarnations of them in your classpath) HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in Europe! www.ffii.org www.nosoftwarepatents.org _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users |
|
|
RE: RE: RE: RE: PostGIS - hibernate - EJB3Thanks Markus for responding.
In the meantime I found the same answer you are suggesting elsewhere: http://postgis.refractions.net/pipermail/postgis-users/2005-March/007153.htm l I just pass it, so other might be helped by it too. -----Original Message----- From: postgis-users-bounces@... [mailto:postgis-users-bounces@...] On Behalf Of Markus Schaber Sent: samedi 25 novembre 2006 10:16 To: PostGIS Users Discussion Subject: Re: [postgis-users] RE: RE: RE: PostGIS - hibernate - EJB3 Hi, Norman Barker wrote: > 2. In the thread here, people are using: > <driver-class>org.postgis.DriverWrapper</driver-class> > When I do the same, I get a "No suitable driver" exception. [...] > 3. I wanted to use the GeometryType that is packed in PostGIS 1.1.5. > After generating the new JAR and replacing the old one by this one, I > start getting new exceptions: > The class org.postgis.PGbox3d does not implement > org.postgresql.util.PGobject. Those 2 things look like a classpath/classloader problem. You have to make sure that the postgis.jar and the postgresql-jdbc.jar are available via the same classloader (and that you don't have two incarnations of them in your classpath) HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in Europe! www.ffii.org www.nosoftwarepatents.org _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users |
|
|
RE: PostGIS - hibernate (new postgis.jar)Hi Markus,
The thing I did to be able to continue is I have created a postgis_addon.jar lib that contained only new stuff like BinaryWriter.class and GeometryUserType. And that works. It does not solve the problem, though I can use the latest version of postgis. I tried to use the tip I found in my previous posting by changing the name of the postgresql-jdbc.jar drvier to pg-jdbc.jar driver with my new build postgis2.jar (version 1.1.5) I did not help. If I remove the 2 stub files (PGConnection and Connection) from postgis2.jar : same result. It stucks again on "No suitable driver". If I replace the postgis2.jar by postgis.jar(1.1.0) and postgis_addon.jar by changing the settings on the classpath, everything works again. So, I assume there is a thing in postgis2.jar. And to create my postgis2.jar, I made a separate project in Eclipse, created a jar file of almost all java files(exl examples). This should do it, no ? Anyway, I included my postgis2.jar so maybe one can replace his one with mine and see what that does. Or maybe one sees what I am doing wrong elsewhere... TIA, Jan -----Original Message----- From: postgis-users-bounces@... [mailto:postgis-users-bounces@...] On Behalf Of Markus Schaber Sent: samedi 25 novembre 2006 10:16 To: PostGIS Users Discussion Subject: Re: [postgis-users] RE: RE: RE: PostGIS - hibernate - EJB3 Hi, Norman Barker wrote: > 2. In the thread here, people are using: > <driver-class>org.postgis.DriverWrapper</driver-class> > When I do the same, I get a "No suitable driver" exception. [...] > 3. I wanted to use the GeometryType that is packed in PostGIS 1.1.5. > After generating the new JAR and replacing the old one by this one, I > start getting new exceptions: > The class org.postgis.PGbox3d does not implement > org.postgresql.util.PGobject. Those 2 things look like a classpath/classloader problem. You have to make sure that the postgis.jar and the postgresql-jdbc.jar are available via the same classloader (and that you don't have two incarnations of them in your classpath) HTH, Markus -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in Europe! www.ffii.org www.nosoftwarepatents.org _______________________________________________ postgis-users mailing list postgis-users@... http://postgis.refractions.net/mailman/listinfo/postgis-users |
|
|
|
|
|
RE: PostGIS - hibernate (new postgis.jar)Thankyou all for the support.
I am using EJB3 with PostgreSQL & JBoss. Read through the tutorial on svn by Norman Barker. I compiled the GeometryType java file in org.postgis.hibernate and included the org.postgis.hibernate package in my classpath and the whole thing worked. Since the last post on this forum was in November 2006, i wanted to know that is there any change in the method to handle gis data from postgresql tables using ejb3 architecture? Is the GeometryType class by Norman included in the latest release of postgis.jar or should it be included seperately like i mentioned above? Thanks again
|
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |