How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?

lads
Dear all,

This is my set up:

    PostgreSQL 9.3
    PostGIS 2.1.4
    Eclipse Mars
    Hibernate Tools 5.0
    Hibernate Spatial 4.3

I also added postgis-jdbc.jar and jts.jarto the build path.

The .cfg.xml file opens with:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<hibernate-configuration>
    <session-factory>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.password">the_pass</property>
    <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/the_db</property>
    <property name="hibernate.connection.username">me</property>
    <property name="hibernate.default_schema">the_schema</property>
    <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect"</property>
    <!-- "Import" the mapping resources here -->

In the reveng.xml file, the tables including geometry type fields are explicitly declared with table-filter elements:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
    [...]
    <table-filter match-name="coordinates"></table-filter>
    <table-filter match-name="polygon"></table-filter>
</hibernate-reverse-engineering>

The Hibernate code generation configuration is creating POJOs with this kind of properties and methods for geometry type fields:

private Serializable geom;

public Serializable getGeom() {
        return this.geom;
}

public void setGeom(Serializable geom) {
        this.geom = geom;
}

In the Hibernate Spatial tutorial, geometry fields are mapped to JTS types, such as (com.vividsolutions.jts.geom.Point). Therefore with this code it is not possible to follow the mechanisms proposed there to retrieve/update spatial fields.

Is it possible to tweak the Hibernate configuration somehow for it to generate mappings from spatial fields to JTS types? Or must these generated Serializable properties be used instead?
Thank you,

Luís

Sent from ProtonMail, encrypted email based in Switzerland.

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?

Karel Maesen
Administrator
I don’t know anything about this Reverse Engineering stuff, but if you’re using Hibernate 5.x your setup is incorrect.

You definitely should remove Hibernate Spatial 4.3 and the postgis-jdbc.jar. Hibernate now has Hibernate Spatial as a module (artifactId == hibernate-spatial), and you should use the version matching you hibernate version.

Also, you can’t specify two dialects. Use the org.hibernate.spatial.dialect.postgis.PostgisDialect.

In your POJO’s you should end up with com.vividsolutions.jts.geom.Geometry-valued properties, not Serializable.

Hope this helps,

Regards,

Karel



> On 20 Feb 2016, at 16:18, Luí­s de Sousa <[hidden email]> wrote:
>
> Dear all,
>
> This is my set up:
>
>     PostgreSQL 9.3
>     PostGIS 2.1.4
>     Eclipse Mars
>     Hibernate Tools 5.0
>     Hibernate Spatial 4.3
>
> I also added postgis-jdbc.jar and jts.jarto the build path.
>
> The .cfg.xml file opens with:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-configuration PUBLIC
>         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
>         "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
> <hibernate-configuration>
>     <session-factory>
>     <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
>     <property name="hibernate.connection.password">the_pass</property>
>     <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/the_db</property>
>     <property name="hibernate.connection.username">me</property>
>     <property name="hibernate.default_schema">the_schema</property>
>     <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
>     <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect"</property>
>     <!-- "Import" the mapping resources here -->
>
> In the reveng.xml file, the tables including geometry type fields are explicitly declared with table-filter elements:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
> <hibernate-reverse-engineering>
>     [...]
>     <table-filter match-name="coordinates"></table-filter>
>     <table-filter match-name="polygon"></table-filter>
> </hibernate-reverse-engineering>
>
> The Hibernate code generation configuration is creating POJOs with this kind of properties and methods for geometry type fields:
>
> private Serializable geom;
>
> public Serializable getGeom() {
>         return this.geom;
> }
>
> public void setGeom(Serializable geom) {
>         this.geom = geom;
> }
>
> In the Hibernate Spatial tutorial, geometry fields are mapped to JTS types, such as (com.vividsolutions.jts.geom.Point). Therefore with this code it is not possible to follow the mechanisms proposed there to retrieve/update spatial fields.
>
> Is it possible to tweak the Hibernate configuration somehow for it to generate mappings from spatial fields to JTS types? Or must these generated Serializable properties be used instead?
> Thank you,
>
> Luís
>
> Sent from ProtonMail, encrypted email based in Switzerland.
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?

lads
HI Karel, thank you for the reply.

I modified the build path, removed Postgis and Hibernate 4.3 and added Hibernate 5.0.7 (hard to find since it is not referenced in the web site). The cfg.xml now looks like

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<hibernate-configuration>
    <session-factory>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.password">my_pass</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/centaur</property>
        <property name="hibernate.connection.username">desouslu</property>
        <property name="hibernate.default_schema">the_schema</property>
        <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</property>
        <mapping resource="Node.hbm.xml"/>
<mapping resource="Link.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

With this configuration I get the exception below when I run the code generation:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.ClassNotFoundException: org.geolatte.geom.codec.db.oracle.ConnectionFinder
org.geolatte.geom.codec.db.oracle.ConnectionFinder

Apparently, I am missing some spatial library. Any idea which?

Thank you,

Luís

Sent from ProtonMail, encrypted email based in Switzerland.


-------- Original Message --------
Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
Local Time: February 20, 2016 4:29 pm
UTC Time: February 20, 2016 3:29 PM

I don’t know anything about this Reverse Engineering stuff, but if you’re using Hibernate 5.x your setup is incorrect.

You definitely should remove Hibernate Spatial 4.3 and the postgis-jdbc.jar. Hibernate now has Hibernate Spatial as a module (artifactId == hibernate-spatial), and you should use the version matching you hibernate version.

Also, you can’t specify two dialects. Use the org.hibernate.spatial.dialect.postgis.PostgisDialect.

In your POJO’s you should end up with com.vividsolutions.jts.geom.Geometry-valued properties, not Serializable.

Hope this helps,

Regards,

Karel



> On 20 Feb 2016, at 16:18, Luí­s de Sousa <[hidden email]> wrote:
>
> Dear all,
>
> This is my set up:
>
> PostgreSQL 9.3
> PostGIS 2.1.4
> Eclipse Mars
> Hibernate Tools 5.0
> Hibernate Spatial 4.3
>
> I also added postgis-jdbc.jar and jts.jarto the build path.
>
> The .cfg.xml file opens with:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-configuration PUBLIC
> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
> "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
> <hibernate-configuration>
> <session-factory>
> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
> <property name="hibernate.connection.password">the_pass</property>
> <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/the_db</property>
> <property name="hibernate.connection.username">me</property>
> <property name="hibernate.default_schema">the_schema</property>
> <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
> <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect"</property>
> <!-- "Import" the mapping resources here -->
>
> In the reveng.xml file, the tables including geometry type fields are explicitly declared with table-filter elements:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
> <hibernate-reverse-engineering>
> [...]
> <table-filter match-name="coordinates"></table-filter>
> <table-filter match-name="polygon"></table-filter>
> </hibernate-reverse-engineering>
>
> The Hibernate code generation configuration is creating POJOs with this kind of properties and methods for geometry type fields:
>
> private Serializable geom;
>
> public Serializable getGeom() {
> return this.geom;
> }
>
> public void setGeom(Serializable geom) {
> this.geom = geom;
> }
>
> In the Hibernate Spatial tutorial, geometry fields are mapped to JTS types, such as (com.vividsolutions.jts.geom.Point). Therefore with this code it is not possible to follow the mechanisms proposed there to retrieve/update spatial fields.
>
> Is it possible to tweak the Hibernate configuration somehow for it to generate mappings from spatial fields to JTS types? Or must these generated Serializable properties be used instead?
> Thank you,
>
> Luís
>
> Sent from ProtonMail, encrypted email based in Switzerland.
> _______________________________________________
> hibernatespatial-users mailing list
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users




_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?

lads
Hello again,

I was able to identify the missing library: geolatte. I thus added geolatte-geom-1.0.jar to the build path and now the code generation is running. However, I am still getting the Serializable fields:

public class Link implements java.io.Serializable {

private int id;
private String name;
private Serializable geom;

public Link() {
}

[...]

public Serializable getGeom() {
return this.geom;
}

public void setGeom(Serializable geom) {
this.geom = geom;
}

}

What else do I need to do to get Gemoetry tyoe fields, getter and setters?

Thank you,

Luís

Sent from ProtonMail, encrypted email based in Switzerland.


-------- Original Message --------
Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
Local Time: February 22, 2016 9:05 am
UTC Time: February 22, 2016 8:05 AM

HI Karel, thank you for the reply.

I modified the build path, removed Postgis and Hibernate 4.3 and added Hibernate 5.0.7 (hard to find since it is not referenced in the web site). The cfg.xml now looks like

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<hibernate-configuration>
    <session-factory>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.password">my_pass</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/centaur</property>
        <property name="hibernate.connection.username">desouslu</property>
        <property name="hibernate.default_schema">the_schema</property>
        <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</property>
        <mapping resource="Node.hbm.xml"/>
<mapping resource="Link.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

With this configuration I get the exception below when I run the code generation:

java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
org/geolatte/geom/codec/db/oracle/ConnectionFinder
java.lang.ClassNotFoundException: org.geolatte.geom.codec.db.oracle.ConnectionFinder
org.geolatte.geom.codec.db.oracle.ConnectionFinder

Apparently, I am missing some spatial library. Any idea which?

Thank you,

Luís

Sent from ProtonMail, encrypted email based in Switzerland.


-------- Original Message --------
Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
Local Time: February 20, 2016 4:29 pm
UTC Time: February 20, 2016 3:29 PM

I don’t know anything about this Reverse Engineering stuff, but if you’re using Hibernate 5.x your setup is incorrect.

You definitely should remove Hibernate Spatial 4.3 and the postgis-jdbc.jar. Hibernate now has Hibernate Spatial as a module (artifactId == hibernate-spatial), and you should use the version matching you hibernate version.

Also, you can’t specify two dialects. Use the org.hibernate.spatial.dialect.postgis.PostgisDialect.

In your POJO’s you should end up with com.vividsolutions.jts.geom.Geometry-valued properties, not Serializable.

Hope this helps,

Regards,

Karel



> On 20 Feb 2016, at 16:18, Luí­s de Sousa <[hidden email]> wrote:
>
> Dear all,
>
> This is my set up:
>
> PostgreSQL 9.3
> PostGIS 2.1.4
> Eclipse Mars
> Hibernate Tools 5.0
> Hibernate Spatial 4.3
>
> I also added postgis-jdbc.jar and jts.jarto the build path.
>
> The .cfg.xml file opens with:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-configuration PUBLIC
> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
> "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
> <hibernate-configuration>
> <session-factory>
> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
> <property name="hibernate.connection.password">the_pass</property>
> <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/the_db</property>
> <property name="hibernate.connection.username">me</property>
> <property name="hibernate.default_schema">the_schema</property>
> <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
> <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect"</property>
> <!-- "Import" the mapping resources here -->
>
> In the reveng.xml file, the tables including geometry type fields are explicitly declared with table-filter elements:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
> <hibernate-reverse-engineering>
> [...]
> <table-filter match-name="coordinates"></table-filter>
> <table-filter match-name="polygon"></table-filter>
> </hibernate-reverse-engineering>
>
> The Hibernate code generation configuration is creating POJOs with this kind of properties and methods for geometry type fields:
>
> private Serializable geom;
>
> public Serializable getGeom() {
> return this.geom;
> }
>
> public void setGeom(Serializable geom) {
> this.geom = geom;
> }
>
> In the Hibernate Spatial tutorial, geometry fields are mapped to JTS types, such as (com.vividsolutions.jts.geom.Point). Therefore with this code it is not possible to follow the mechanisms proposed there to retrieve/update spatial fields.
>
> Is it possible to tweak the Hibernate configuration somehow for it to generate mappings from spatial fields to JTS types? Or must these generated Serializable properties be used instead?
> Thank you,
>
> Luís
>
> Sent from ProtonMail, encrypted email based in Switzerland.
> _______________________________________________
> hibernatespatial-users mailing list
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users





_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?

Karel Maesen
Administrator
Hi,

I don’t know how the reverse engineering works, but apparently it fails to match the JDBC type to the Spatial types. You should configure it so that java.sql.Types.Other (which is what JDBC reports the geometry columns as in the case of Postgis) are mapped to the JTSGeometryType (name is :’jts_geometry’).

Regards,

Karel


> On 23 Feb 2016, at 08:32, Luí­s de Sousa <[hidden email]> wrote:
>
> Hello again,
>
> I was able to identify the missing library: geolatte. I thus added geolatte-geom-1.0.jar to the build path and now the code generation is running. However, I am still getting the Serializable fields:
>
> public class Link implements java.io.Serializable {
>
> private int id;
> private String name;
> private Serializable geom;
>
> public Link() {
> }
>
> [...]
>
> public Serializable getGeom() {
> return this.geom;
> }
>
> public void setGeom(Serializable geom) {
> this.geom = geom;
> }
>
> }
>
> What else do I need to do to get Gemoetry tyoe fields, getter and setters?
>
> Thank you,
>
> Luís
>
> Sent from ProtonMail, encrypted email based in Switzerland.
>
>
>> -------- Original Message --------
>> Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
>> Local Time: February 22, 2016 9:05 am
>> UTC Time: February 22, 2016 8:05 AM
>> From: [hidden email]
>> To: [hidden email]
>> CC: [hidden email]
>>
>> HI Karel, thank you for the reply.
>>
>> I modified the build path, removed Postgis and Hibernate 4.3 and added Hibernate 5.0.7 (hard to find since it is not referenced in the web site). The cfg.xml now looks like
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE hibernate-configuration PUBLIC
>> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
>> "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
>> <hibernate-configuration>
>>     <session-factory>
>>     <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
>>         <property name="hibernate.connection.password">my_pass</property>
>>         <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/centaur</property>
>>         <property name="hibernate.connection.username">desouslu</property>
>>         <property name="hibernate.default_schema">the_schema</property>
>>         <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</property>
>>         <mapping resource="Node.hbm.xml"/>
>> <mapping resource="Link.hbm.xml"/>
>>     </session-factory>
>> </hibernate-configuration>
>>
>> With this configuration I get the exception below when I run the code generation:
>>
>> java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.ClassNotFoundException: org.geolatte.geom.codec.db.oracle.ConnectionFinder
>> org.geolatte.geom.codec.db.oracle.ConnectionFinder
>>
>> Apparently, I am missing some spatial library. Any idea which?
>>
>> Thank you,
>>
>> Luís
>>
>> Sent from ProtonMail, encrypted email based in Switzerland.
>>
>>
>>> -------- Original Message --------
>>> Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
>>> Local Time: February 20, 2016 4:29 pm
>>> UTC Time: February 20, 2016 3:29 PM
>>> From: [hidden email]
>>> To: [hidden email],[hidden email]
>>>
>>> I don’t know anything about this Reverse Engineering stuff, but if you’re using Hibernate 5.x your setup is incorrect.
>>>
>>> You definitely should remove Hibernate Spatial 4.3 and the postgis-jdbc.jar. Hibernate now has Hibernate Spatial as a module (artifactId == hibernate-spatial), and you should use the version matching you hibernate version.
>>>
>>> Also, you can’t specify two dialects. Use the org.hibernate.spatial.dialect.postgis.PostgisDialect.
>>>
>>> In your POJO’s you should end up with com.vividsolutions.jts.geom.Geometry-valued properties, not Serializable.
>>>
>>> Hope this helps,
>>>
>>> Regards,
>>>
>>> Karel
>>>
>>>
>>>
>>> > On 20 Feb 2016, at 16:18, Luí­s de Sousa <[hidden email]> wrote:
>>> >
>>> > Dear all,
>>> >
>>> > This is my set up:
>>> >
>>> > PostgreSQL 9.3
>>> > PostGIS 2.1.4
>>> > Eclipse Mars
>>> > Hibernate Tools 5.0
>>> > Hibernate Spatial 4.3
>>> >
>>> > I also added postgis-jdbc.jar and jts.jarto the build path.
>>> >
>>> > The .cfg.xml file opens with:
>>> >
>>> > <?xml version="1.0" encoding="UTF-8"?>
>>> > <!DOCTYPE hibernate-configuration PUBLIC
>>> > "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
>>> > "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
>>> > <hibernate-configuration>
>>> > <session-factory>
>>> > <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
>>> > <property name="hibernate.connection.password">the_pass</property>
>>> > <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/the_db</property>
>>> > <property name="hibernate.connection.username">me</property>
>>> > <property name="hibernate.default_schema">the_schema</property>
>>> > <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
>>> > <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect"</property>
>>> > <!-- "Import" the mapping resources here -->
>>> >
>>> > In the reveng.xml file, the tables including geometry type fields are explicitly declared with table-filter elements:
>>> >
>>> > <?xml version="1.0" encoding="UTF-8"?>
>>> > <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
>>> > <hibernate-reverse-engineering>
>>> > [...]
>>> > <table-filter match-name="coordinates"></table-filter>
>>> > <table-filter match-name="polygon"></table-filter>
>>> > </hibernate-reverse-engineering>
>>> >
>>> > The Hibernate code generation configuration is creating POJOs with this kind of properties and methods for geometry type fields:
>>> >
>>> > private Serializable geom;
>>> >
>>> > public Serializable getGeom() {
>>> > return this.geom;
>>> > }
>>> >
>>> > public void setGeom(Serializable geom) {
>>> > this.geom = geom;
>>> > }
>>> >
>>> > In the Hibernate Spatial tutorial, geometry fields are mapped to JTS types, such as (com.vividsolutions.jts.geom.Point). Therefore with this code it is not possible to follow the mechanisms proposed there to retrieve/update spatial fields.
>>> >
>>> > Is it possible to tweak the Hibernate configuration somehow for it to generate mappings from spatial fields to JTS types? Or must these generated Serializable properties be used instead?
>>> > Thank you,
>>> >
>>> > Luís
>>> >
>>> > Sent from ProtonMail, encrypted email based in Switzerland.
>>> > _______________________________________________
>>> > hibernatespatial-users mailing list
>>> > [hidden email]
>>> > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>>>
>>>
>>
>

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?

lads
Dear Karel, thank you for the continued support.

I went through the reverse engineering documentation and added this to my reveng.xml file:

<type-mapping>
<sql-type jdbc-type="java.sql.Types.OTHER" hibernate-type="JTSGeometryType"/>
</type-mapping>

However, when I run the configuration I receive back this exception:

org.hibernate.MappingException: jdbc-type: java.sql.Types.OTHER is not a known JDBC Type nor a valid number

Any ideas on what may be wrong? Thank you,

Luís


Sent from ProtonMail, encrypted email based in Switzerland.


-------- Original Message --------
Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
Local Time: February 23, 2016 10:24 am
UTC Time: February 23, 2016 9:24 AM

Hi,

I don’t know how the reverse engineering works, but apparently it fails to match the JDBC type to the Spatial types. You should configure it so that java.sql.Types.Other (which is what JDBC reports the geometry columns as in the case of Postgis) are mapped to the JTSGeometryType (name is :’jts_geometry’).

Regards,

Karel


> On 23 Feb 2016, at 08:32, Luí­s de Sousa <[hidden email]> wrote:
>
> Hello again,
>
> I was able to identify the missing library: geolatte. I thus added geolatte-geom-1.0.jar to the build path and now the code generation is running. However, I am still getting the Serializable fields:
>
> public class Link implements java.io.Serializable {
>
> private int id;
> private String name;
> private Serializable geom;
>
> public Link() {
> }
>
> [...]
>
> public Serializable getGeom() {
> return this.geom;
> }
>
> public void setGeom(Serializable geom) {
> this.geom = geom;
> }
>
> }
>
> What else do I need to do to get Gemoetry tyoe fields, getter and setters?
>
> Thank you,
>
> Luís
>
> Sent from ProtonMail, encrypted email based in Switzerland.
>
>
>> -------- Original Message --------
>> Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
>> Local Time: February 22, 2016 9:05 am
>> UTC Time: February 22, 2016 8:05 AM
>> From: [hidden email]
>>
>> HI Karel, thank you for the reply.
>>
>> I modified the build path, removed Postgis and Hibernate 4.3 and added Hibernate 5.0.7 (hard to find since it is not referenced in the web site). The cfg.xml now looks like
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE hibernate-configuration PUBLIC
>> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
>> "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
>> <hibernate-configuration>
>> <session-factory>
>> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
>> <property name="hibernate.connection.password">my_pass</property>
>> <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/centaur</property>
>> <property name="hibernate.connection.username">desouslu</property>
>> <property name="hibernate.default_schema">the_schema</property>
>> <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</property>
>> <mapping resource="Node.hbm.xml"/>
>> <mapping resource="Link.hbm.xml"/>
>> </session-factory>
>> </hibernate-configuration>
>>
>> With this configuration I get the exception below when I run the code generation:
>>
>> java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> java.lang.ClassNotFoundException: org.geolatte.geom.codec.db.oracle.ConnectionFinder
>> org.geolatte.geom.codec.db.oracle.ConnectionFinder
>>
>> Apparently, I am missing some spatial library. Any idea which?
>>
>> Thank you,
>>
>> Luís
>>
>> Sent from ProtonMail, encrypted email based in Switzerland.
>>
>>
>>> -------- Original Message --------
>>> Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
>>> Local Time: February 20, 2016 4:29 pm
>>> UTC Time: February 20, 2016 3:29 PM
>>> From: [hidden email]
>>>
>>> I don’t know anything about this Reverse Engineering stuff, but if you’re using Hibernate 5.x your setup is incorrect.
>>>
>>> You definitely should remove Hibernate Spatial 4.3 and the postgis-jdbc.jar. Hibernate now has Hibernate Spatial as a module (artifactId == hibernate-spatial), and you should use the version matching you hibernate version.
>>>
>>> Also, you can’t specify two dialects. Use the org.hibernate.spatial.dialect.postgis.PostgisDialect.
>>>
>>> In your POJO’s you should end up with com.vividsolutions.jts.geom.Geometry-valued properties, not Serializable.
>>>
>>> Hope this helps,
>>>
>>> Regards,
>>>
>>> Karel
>>>
>>>
>>>
>>> > On 20 Feb 2016, at 16:18, Luí­s de Sousa <[hidden email]> wrote:
>>> >
>>> > Dear all,
>>> >
>>> > This is my set up:
>>> >
>>> > PostgreSQL 9.3
>>> > PostGIS 2.1.4
>>> > Eclipse Mars
>>> > Hibernate Tools 5.0
>>> > Hibernate Spatial 4.3
>>> >
>>> > I also added postgis-jdbc.jar and jts.jarto the build path.
>>> >
>>> > The .cfg.xml file opens with:
>>> >
>>> > <?xml version="1.0" encoding="UTF-8"?>
>>> > <!DOCTYPE hibernate-configuration PUBLIC
>>> > "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
>>> > "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
>>> > <hibernate-configuration>
>>> > <session-factory>
>>> > <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
>>> > <property name="hibernate.connection.password">the_pass</property>
>>> > <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/the_db</property>
>>> > <property name="hibernate.connection.username">me</property>
>>> > <property name="hibernate.default_schema">the_schema</property>
>>> > <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
>>> > <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect"</property>
>>> > <!-- "Import" the mapping resources here -->
>>> >
>>> > In the reveng.xml file, the tables including geometry type fields are explicitly declared with table-filter elements:
>>> >
>>> > <?xml version="1.0" encoding="UTF-8"?>
>>> > <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
>>> > <hibernate-reverse-engineering>
>>> > [...]
>>> > <table-filter match-name="coordinates"></table-filter>
>>> > <table-filter match-name="polygon"></table-filter>
>>> > </hibernate-reverse-engineering>
>>> >
>>> > The Hibernate code generation configuration is creating POJOs with this kind of properties and methods for geometry type fields:
>>> >
>>> > private Serializable geom;
>>> >
>>> > public Serializable getGeom() {
>>> > return this.geom;
>>> > }
>>> >
>>> > public void setGeom(Serializable geom) {
>>> > this.geom = geom;
>>> > }
>>> >
>>> > In the Hibernate Spatial tutorial, geometry fields are mapped to JTS types, such as (com.vividsolutions.jts.geom.Point). Therefore with this code it is not possible to follow the mechanisms proposed there to retrieve/update spatial fields.
>>> >
>>> > Is it possible to tweak the Hibernate configuration somehow for it to generate mappings from spatial fields to JTS types? Or must these generated Serializable properties be used instead?
>>> > Thank you,
>>> >
>>> > Luís
>>> >
>>> > Sent from ProtonMail, encrypted email based in Switzerland.
>>> > _______________________________________________
>>> > hibernatespatial-users mailing list
>>> > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>>>
>>>
>>
>




_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?

Karel Maesen
Administrator
The JDK 1.6 clearly has defined java.sql.Types.OTHER as:

public static final int OTHER = 1111;

So if this is not known, or accepted by the reverse engineering tool, you should take it up with them.

Maybe it is worth trying to map JAVA_OBJECT = 2000 to JTSGeometryType. Might just work.

Karel


> On 25 Feb 2016, at 11:48, Luí­s de Sousa <[hidden email]> wrote:
>
> Dear Karel, thank you for the continued support.
>
> I went through the reverse engineering documentation and added this to my reveng.xml file:
>
> <type-mapping>
> <sql-type jdbc-type="java.sql.Types.OTHER" hibernate-type="JTSGeometryType"/>
> </type-mapping>
>
> However, when I run the configuration I receive back this exception:
>
> org.hibernate.MappingException: jdbc-type: java.sql.Types.OTHER is not a known JDBC Type nor a valid number
>
> Any ideas on what may be wrong? Thank you,
>
> Luís
>
>
> Sent from ProtonMail, encrypted email based in Switzerland.
>
>
>> -------- Original Message --------
>> Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
>> Local Time: February 23, 2016 10:24 am
>> UTC Time: February 23, 2016 9:24 AM
>> From: [hidden email]
>> To: [hidden email]
>> CC: [hidden email]
>>
>> Hi,
>>
>> I don’t know how the reverse engineering works, but apparently it fails to match the JDBC type to the Spatial types. You should configure it so that java.sql.Types.Other (which is what JDBC reports the geometry columns as in the case of Postgis) are mapped to the JTSGeometryType (name is :’jts_geometry’).
>>
>> Regards,
>>
>> Karel
>>
>>
>> > On 23 Feb 2016, at 08:32, Luí­s de Sousa <[hidden email]> wrote:
>> >
>> > Hello again,
>> >
>> > I was able to identify the missing library: geolatte. I thus added geolatte-geom-1.0.jar to the build path and now the code generation is running. However, I am still getting the Serializable fields:
>> >
>> > public class Link implements java.io.Serializable {
>> >
>> > private int id;
>> > private String name;
>> > private Serializable geom;
>> >
>> > public Link() {
>> > }
>> >
>> > [...]
>> >
>> > public Serializable getGeom() {
>> > return this.geom;
>> > }
>> >
>> > public void setGeom(Serializable geom) {
>> > this.geom = geom;
>> > }
>> >
>> > }
>> >
>> > What else do I need to do to get Gemoetry tyoe fields, getter and setters?
>> >
>> > Thank you,
>> >
>> > Luís
>> >
>> > Sent from ProtonMail, encrypted email based in Switzerland.
>> >
>> >
>> >> -------- Original Message --------
>> >> Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
>> >> Local Time: February 22, 2016 9:05 am
>> >> UTC Time: February 22, 2016 8:05 AM
>> >> From: [hidden email]
>> >> To: [hidden email]
>> >> CC: [hidden email]
>> >>
>> >> HI Karel, thank you for the reply.
>> >>
>> >> I modified the build path, removed Postgis and Hibernate 4.3 and added Hibernate 5.0.7 (hard to find since it is not referenced in the web site). The cfg.xml now looks like
>> >>
>> >> <?xml version="1.0" encoding="UTF-8"?>
>> >> <!DOCTYPE hibernate-configuration PUBLIC
>> >> "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
>> >> "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
>> >> <hibernate-configuration>
>> >> <session-factory>
>> >> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
>> >> <property name="hibernate.connection.password">my_pass</property>
>> >> <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/centaur</property>
>> >> <property name="hibernate.connection.username">desouslu</property>
>> >> <property name="hibernate.default_schema">the_schema</property>
>> >> <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect</property>
>> >> <mapping resource="Node.hbm.xml"/>
>> >> <mapping resource="Link.hbm.xml"/>
>> >> </session-factory>
>> >> </hibernate-configuration>
>> >>
>> >> With this configuration I get the exception below when I run the code generation:
>> >>
>> >> java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> >> java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> >> java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> >> java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> >> java.lang.NoClassDefFoundError: org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> >> org/geolatte/geom/codec/db/oracle/ConnectionFinder
>> >> java.lang.ClassNotFoundException: org.geolatte.geom.codec.db.oracle.ConnectionFinder
>> >> org.geolatte.geom.codec.db.oracle.ConnectionFinder
>> >>
>> >> Apparently, I am missing some spatial library. Any idea which?
>> >>
>> >> Thank you,
>> >>
>> >> Luís
>> >>
>> >> Sent from ProtonMail, encrypted email based in Switzerland.
>> >>
>> >>
>> >>> -------- Original Message --------
>> >>> Subject: Re: [hibernatespatial-users] How to reverse engineer a PostGIS enabled database with Eclipse Hibernate Tools?
>> >>> Local Time: February 20, 2016 4:29 pm
>> >>> UTC Time: February 20, 2016 3:29 PM
>> >>> From: [hidden email]
>> >>> To: [hidden email],[hidden email]
>> >>>
>> >>> I don’t know anything about this Reverse Engineering stuff, but if you’re using Hibernate 5.x your setup is incorrect.
>> >>>
>> >>> You definitely should remove Hibernate Spatial 4.3 and the postgis-jdbc.jar. Hibernate now has Hibernate Spatial as a module (artifactId == hibernate-spatial), and you should use the version matching you hibernate version.
>> >>>
>> >>> Also, you can’t specify two dialects. Use the org.hibernate.spatial.dialect.postgis.PostgisDialect.
>> >>>
>> >>> In your POJO’s you should end up with com.vividsolutions.jts.geom.Geometry-valued properties, not Serializable.
>> >>>
>> >>> Hope this helps,
>> >>>
>> >>> Regards,
>> >>>
>> >>> Karel
>> >>>
>> >>>
>> >>>
>> >>> > On 20 Feb 2016, at 16:18, Luí­s de Sousa <[hidden email]> wrote:
>> >>> >
>> >>> > Dear all,
>> >>> >
>> >>> > This is my set up:
>> >>> >
>> >>> > PostgreSQL 9.3
>> >>> > PostGIS 2.1.4
>> >>> > Eclipse Mars
>> >>> > Hibernate Tools 5.0
>> >>> > Hibernate Spatial 4.3
>> >>> >
>> >>> > I also added postgis-jdbc.jar and jts.jarto the build path.
>> >>> >
>> >>> > The .cfg.xml file opens with:
>> >>> >
>> >>> > <?xml version="1.0" encoding="UTF-8"?>
>> >>> > <!DOCTYPE hibernate-configuration PUBLIC
>> >>> > "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
>> >>> > "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
>> >>> > <hibernate-configuration>
>> >>> > <session-factory>
>> >>> > <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
>> >>> > <property name="hibernate.connection.password">the_pass</property>
>> >>> > <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/the_db</property>
>> >>> > <property name="hibernate.connection.username">me</property>
>> >>> > <property name="hibernate.default_schema">the_schema</property>
>> >>> > <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
>> >>> > <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect"</property>
>> >>> > <!-- "Import" the mapping resources here -->
>> >>> >
>> >>> > In the reveng.xml file, the tables including geometry type fields are explicitly declared with table-filter elements:
>> >>> >
>> >>> > <?xml version="1.0" encoding="UTF-8"?>
>> >>> > <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
>> >>> > <hibernate-reverse-engineering>
>> >>> > [...]
>> >>> > <table-filter match-name="coordinates"></table-filter>
>> >>> > <table-filter match-name="polygon"></table-filter>
>> >>> > </hibernate-reverse-engineering>
>> >>> >
>> >>> > The Hibernate code generation configuration is creating POJOs with this kind of properties and methods for geometry type fields:
>> >>> >
>> >>> > private Serializable geom;
>> >>> >
>> >>> > public Serializable getGeom() {
>> >>> > return this.geom;
>> >>> > }
>> >>> >
>> >>> > public void setGeom(Serializable geom) {
>> >>> > this.geom = geom;
>> >>> > }
>> >>> >
>> >>> > In the Hibernate Spatial tutorial, geometry fields are mapped to JTS types, such as (com.vividsolutions.jts.geom.Point). Therefore with this code it is not possible to follow the mechanisms proposed there to retrieve/update spatial fields.
>> >>> >
>> >>> > Is it possible to tweak the Hibernate configuration somehow for it to generate mappings from spatial fields to JTS types? Or must these generated Serializable properties be used instead?
>> >>> > Thank you,
>> >>> >
>> >>> > Luís
>> >>> >
>> >>> > Sent from ProtonMail, encrypted email based in Switzerland.
>> >>> > _______________________________________________
>> >>> > hibernatespatial-users mailing list
>> >>> > [hidden email]
>> >>> > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>> >>>
>> >>>
>> >>
>> >
>>
>>
>

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users