Having both hibernate-spatial-oracle* and hibernate-spatial-postgres-*.jar files in the classpath

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

Having both hibernate-spatial-oracle* and hibernate-spatial-postgres-*.jar files in the classpath

Coquelicot-2
Dear mailing list members,

I have noticed a strange behaviour of the Hibernate Spatial: when both
of the JAR files mentioned above are in the classpath and Hibernate is
configured for PosrgreSQL backend, still the Oracle one is used  - I'm
using c3p0 and connection finder class that gives the c3p0 Oracle
connection. Is that desirable? I thought that Hibernate's
configuration determines which classes are loaded and later used by
Hibernate Spatial. The problem disappears when I remove
'hibernate-spatial-oracle-*.jar' file from the class path...

Best regards,

Lukasz
_______________________________________________
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: Having both hibernate-spatial-oracle* and hibernate-spatial-postgres-*.jar files in the classpath

Juan Marín Otero
I haven't run into this situation since I have never attempted to target both dbs at the same time. I wonder if the configuration file, hibernate-spatial.cfg.xml is of any help here. I have mine set like this:

<?xml version="1.0" encoding="UTF-8"?>
<hibernate-spatial>
    <default_dialect>org.hibernatespatial.oracle.OracleSpatial10gDialect</default_dialect>
</hibernate-spatial>

Perhaps if you tell it to pick up the Postgres dialect it works.



--
Juan Marín Otero
GIS Consultant

-------Visita mi blog en---------------------
http://guachintoneando.blogspot.com
---------------------------------------------------




On Mon, Jul 26, 2010 at 11:23 AM, Coquelicot <[hidden email]> wrote:
Dear mailing list members,

I have noticed a strange behaviour of the Hibernate Spatial: when both
of the JAR files mentioned above are in the classpath and Hibernate is
configured for PosrgreSQL backend, still the Oracle one is used  - I'm
using c3p0 and connection finder class that gives the c3p0 Oracle
connection. Is that desirable? I thought that Hibernate's
configuration determines which classes are loaded and later used by
Hibernate Spatial. The problem disappears when I remove
'hibernate-spatial-oracle-*.jar' file from the class path...

Best regards,

Lukasz
_______________________________________________
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: Having both hibernate-spatial-oracle* and hibernate-spatial-postgres-*.jar files in the classpath

shane
I'm running into this problem, and attacked it without much initial success. I was also expecting HS to use the dialect configured in the hibernate configuration.

I attempted to use the hibernate-spatial.cfg.xml solution proposed by Juan, but then HBSpatialExtention.createSpatialDialect started complaining: "No SpatialDialect provider for persistenceUnit com.blah.blah.CustomDialect."

I then created the META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider file in my application and listed my two custom dialects on two lines. Still no luck.

Any advice on how to do this? I'll dig into the source again soon, but any pointers would be appreciated. Is there any reason that HS doesn't just use the dialect indicated by the Hibernate config?
Reply | Threaded
Open this post in threaded view
|

Re: Having both hibernate-spatial-oracle* and hibernate-spatial-postgres-*.jar files in the classpath

shane
Ah, nevermind. I was putting the DialectProvider registry file into the wrong META-INF. It needs to be in src/main/resources so that it ends up in the classes directory in the target.

Just for reference, if you want to have multiple providers on the classpath, follow Juan's advice and add src/main/resources/hibernate-spatial.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-spatial>           
<default_dialect>org.hibernatespatial.oracle.OracleSpatial10gDialect</default_dialect>
</hibernate-spatial> 

If you need to reference a custom extended dialect here, create dialect providers for your custom dialect (see org.hibernatespatial.sqlserver.DialectProvider for a simple example). Then create src/main/resources/META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider, which contains the names of your custom dialects, one per line like so:

com.axiomalaska.dialects.CustomSQLServerSpatialDialect
com.axiomalaska.dialects.CustomOracle10gSpatialDialect

Everything should work after that, and you should be able to switch dialects just by changing one line in hibernate-spatial.cfg.xml

-Shane

On Thu, Mar 31, 2011 at 4:19 PM, shane <[hidden email]> wrote:
I'm running into this problem, and attacked it without much initial success.
I was also expecting HS to use the dialect configured in the hibernate
configuration.

I attempted to use the hibernate-spatial.cfg.xml solution proposed by Juan,
but then HBSpatialExtention.createSpatialDialect started complaining: "No
SpatialDialect provider for persistenceUnit com.blah.blah.CustomDialect."

I then created the
META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider file in my
application and listed my two custom dialects on two lines. Still no luck.

Any advice on how to do this? I'll dig into the source again soon, but any
pointers would be appreciated. Is there any reason that HS doesn't just use
the dialect indicated by the Hibernate config?

--
View this message in context: http://hibernate-spatial.1140993.n2.nabble.com/Having-both-hibernate-spatial-oracle-and-hibernate-spatial-postgres-jar-files-in-the-classpath-tp5338414p6229025.html
Sent from the Hibernate Spatial - Users mailing list archive at Nabble.com.
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



--
Shane StClair
Software Engineer
Axiom Consulting & Design
523 W 8th Ave
Suite 104
Anchorage, AK 99501
http://www.axiomalaska.com

_______________________________________________
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: Having both hibernate-spatial-oracle* and hibernate-spatial-postgres-*.jar files in the classpath

yonsonsal
Hi, I'm using Hibernate Spatial 1.0 and I had the same problem.
First I try to annotate the dialect in the @Type
like this:

//Entity
......................................
@Type(type = "org.hibernatespatial.GeometryUserType"
,parameters={@Parameter(name="dialect",value="postgis")})
 public Point getGeometry() {
                return geometry;
        }

But it didn't work :(.
So I decided to debug HS source  and I notice where and when a providers is loaded.
And a I realized that it is loaded whenever you use the Class GeometryUserType.
So if you are using binding parameters in a spatial JPA query like this

hibQuery.setParameter("within", bbox,
                                Hibernate.custom(GeometryUserType.class)).

You must specify which dialect you are using in this parameter binding, or the default Dialect  will be set (oracleDialect in my case).

Fortunately I found another signature of the same method to specify those

Hibernate.custom(GeometryUserType.class,props)
where props is an java.util.Properties with ("dialect","postgis") as unique Name/value pair.

To sumarize I specify in both places the dialect.
In the Entity @Type  annotation
and also in the parameter binding of the JPA Query.

Hope it will be useful.

Regards
Nacho
shane wrote
Ah, nevermind. I was putting the DialectProvider registry file into the
wrong META-INF. It needs to be in src/main/resources so that it ends up in
the classes directory in the target.

Just for reference, if you want to have multiple providers on the classpath,
follow Juan's advice and add src/main/resources/hibernate-spatial.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-spatial>
<default_dialect>org.hibernatespatial.oracle.OracleSpatial10gDialect</default_dialect>
</hibernate-spatial>

If you need to reference a custom extended dialect here, create dialect
providers for your custom dialect (see
org.hibernatespatial.sqlserver.DialectProvider for a simple example). Then
create
src/main/resources/META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider,
which contains the names of your custom dialects, one per line like so:

com.axiomalaska.dialects.CustomSQLServerSpatialDialect
com.axiomalaska.dialects.CustomOracle10gSpatialDialect

Everything should work after that, and you should be able to switch dialects
just by changing one line in hibernate-spatial.cfg.xml

-Shane

On Thu, Mar 31, 2011 at 4:19 PM, shane <[hidden email]> wrote:

> I'm running into this problem, and attacked it without much initial
> success.
> I was also expecting HS to use the dialect configured in the hibernate
> configuration.
>
> I attempted to use the hibernate-spatial.cfg.xml solution proposed by Juan,
> but then HBSpatialExtention.createSpatialDialect started complaining: "No
> SpatialDialect provider for persistenceUnit com.blah.blah.CustomDialect."
>
> I then created the
> META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider file in
> my
> application and listed my two custom dialects on two lines. Still no luck.
>
> Any advice on how to do this? I'll dig into the source again soon, but any
> pointers would be appreciated. Is there any reason that HS doesn't just use
> the dialect indicated by the Hibernate config?
>
> --
> View this message in context:
> http://hibernate-spatial.1140993.n2.nabble.com/Having-both-hibernate-spatial-oracle-and-hibernate-spatial-postgres-jar-files-in-the-classpath-tp5338414p6229025.html
> Sent from the Hibernate Spatial - Users mailing list archive at Nabble.com.
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
>
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>



--
Shane StClair
Software Engineer
Axiom Consulting & Design
523 W 8th Ave
Suite 104
Anchorage, AK 99501
http://www.axiomalaska.com

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
shane wrote
Ah, nevermind. I was putting the DialectProvider registry file into the
wrong META-INF. It needs to be in src/main/resources so that it ends up in
the classes directory in the target.

Just for reference, if you want to have multiple providers on the classpath,
follow Juan's advice and add src/main/resources/hibernate-spatial.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-spatial>
<default_dialect>org.hibernatespatial.oracle.OracleSpatial10gDialect</default_dialect>
</hibernate-spatial>

If you need to reference a custom extended dialect here, create dialect
providers for your custom dialect (see
org.hibernatespatial.sqlserver.DialectProvider for a simple example). Then
create
src/main/resources/META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider,
which contains the names of your custom dialects, one per line like so:

com.axiomalaska.dialects.CustomSQLServerSpatialDialect
com.axiomalaska.dialects.CustomOracle10gSpatialDialect

Everything should work after that, and you should be able to switch dialects
just by changing one line in hibernate-spatial.cfg.xml

-Shane

On Thu, Mar 31, 2011 at 4:19 PM, shane <[hidden email]> wrote:

> I'm running into this problem, and attacked it without much initial
> success.
> I was also expecting HS to use the dialect configured in the hibernate
> configuration.
>
> I attempted to use the hibernate-spatial.cfg.xml solution proposed by Juan,
> but then HBSpatialExtention.createSpatialDialect started complaining: "No
> SpatialDialect provider for persistenceUnit com.blah.blah.CustomDialect."
>
> I then created the
> META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider file in
> my
> application and listed my two custom dialects on two lines. Still no luck.
>
> Any advice on how to do this? I'll dig into the source again soon, but any
> pointers would be appreciated. Is there any reason that HS doesn't just use
> the dialect indicated by the Hibernate config?
>
> --
> View this message in context:
> http://hibernate-spatial.1140993.n2.nabble.com/Having-both-hibernate-spatial-oracle-and-hibernate-spatial-postgres-jar-files-in-the-classpath-tp5338414p6229025.html
> Sent from the Hibernate Spatial - Users mailing list archive at Nabble.com.
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
>
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>



--
Shane StClair
Software Engineer
Axiom Consulting & Design
523 W 8th Ave
Suite 104
Anchorage, AK 99501
http://www.axiomalaska.com

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
shane wrote
Ah, nevermind. I was putting the DialectProvider registry file into the
wrong META-INF. It needs to be in src/main/resources so that it ends up in
the classes directory in the target.

Just for reference, if you want to have multiple providers on the classpath,
follow Juan's advice and add src/main/resources/hibernate-spatial.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-spatial>
<default_dialect>org.hibernatespatial.oracle.OracleSpatial10gDialect</default_dialect>
</hibernate-spatial>

If you need to reference a custom extended dialect here, create dialect
providers for your custom dialect (see
org.hibernatespatial.sqlserver.DialectProvider for a simple example). Then
create
src/main/resources/META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider,
which contains the names of your custom dialects, one per line like so:

com.axiomalaska.dialects.CustomSQLServerSpatialDialect
com.axiomalaska.dialects.CustomOracle10gSpatialDialect

Everything should work after that, and you should be able to switch dialects
just by changing one line in hibernate-spatial.cfg.xml

-Shane

On Thu, Mar 31, 2011 at 4:19 PM, shane <[hidden email]> wrote:

> I'm running into this problem, and attacked it without much initial
> success.
> I was also expecting HS to use the dialect configured in the hibernate
> configuration.
>
> I attempted to use the hibernate-spatial.cfg.xml solution proposed by Juan,
> but then HBSpatialExtention.createSpatialDialect started complaining: "No
> SpatialDialect provider for persistenceUnit com.blah.blah.CustomDialect."
>
> I then created the
> META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider file in
> my
> application and listed my two custom dialects on two lines. Still no luck.
>
> Any advice on how to do this? I'll dig into the source again soon, but any
> pointers would be appreciated. Is there any reason that HS doesn't just use
> the dialect indicated by the Hibernate config?
>
> --
> View this message in context:
> http://hibernate-spatial.1140993.n2.nabble.com/Having-both-hibernate-spatial-oracle-and-hibernate-spatial-postgres-jar-files-in-the-classpath-tp5338414p6229025.html
> Sent from the Hibernate Spatial - Users mailing list archive at Nabble.com.
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
>
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>



--
Shane StClair
Software Engineer
Axiom Consulting & Design
523 W 8th Ave
Suite 104
Anchorage, AK 99501
http://www.axiomalaska.com

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
shane wrote
Ah, nevermind. I was putting the DialectProvider registry file into the
wrong META-INF. It needs to be in src/main/resources so that it ends up in
the classes directory in the target.

Just for reference, if you want to have multiple providers on the classpath,
follow Juan's advice and add src/main/resources/hibernate-spatial.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-spatial>
<default_dialect>org.hibernatespatial.oracle.OracleSpatial10gDialect</default_dialect>
</hibernate-spatial>

If you need to reference a custom extended dialect here, create dialect
providers for your custom dialect (see
org.hibernatespatial.sqlserver.DialectProvider for a simple example). Then
create
src/main/resources/META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider,
which contains the names of your custom dialects, one per line like so:

com.axiomalaska.dialects.CustomSQLServerSpatialDialect
com.axiomalaska.dialects.CustomOracle10gSpatialDialect

Everything should work after that, and you should be able to switch dialects
just by changing one line in hibernate-spatial.cfg.xml

-Shane

On Thu, Mar 31, 2011 at 4:19 PM, shane <[hidden email]> wrote:

> I'm running into this problem, and attacked it without much initial
> success.
> I was also expecting HS to use the dialect configured in the hibernate
> configuration.
>
> I attempted to use the hibernate-spatial.cfg.xml solution proposed by Juan,
> but then HBSpatialExtention.createSpatialDialect started complaining: "No
> SpatialDialect provider for persistenceUnit com.blah.blah.CustomDialect."
>
> I then created the
> META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider file in
> my
> application and listed my two custom dialects on two lines. Still no luck.
>
> Any advice on how to do this? I'll dig into the source again soon, but any
> pointers would be appreciated. Is there any reason that HS doesn't just use
> the dialect indicated by the Hibernate config?
>
> --
> View this message in context:
> http://hibernate-spatial.1140993.n2.nabble.com/Having-both-hibernate-spatial-oracle-and-hibernate-spatial-postgres-jar-files-in-the-classpath-tp5338414p6229025.html
> Sent from the Hibernate Spatial - Users mailing list archive at Nabble.com.
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
>
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>



--
Shane StClair
Software Engineer
Axiom Consulting & Design
523 W 8th Ave
Suite 104
Anchorage, AK 99501
http://www.axiomalaska.com

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
shane wrote
Ah, nevermind. I was putting the DialectProvider registry file into the
wrong META-INF. It needs to be in src/main/resources so that it ends up in
the classes directory in the target.

Just for reference, if you want to have multiple providers on the classpath,
follow Juan's advice and add src/main/resources/hibernate-spatial.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-spatial>
<default_dialect>org.hibernatespatial.oracle.OracleSpatial10gDialect</default_dialect>
</hibernate-spatial>

If you need to reference a custom extended dialect here, create dialect
providers for your custom dialect (see
org.hibernatespatial.sqlserver.DialectProvider for a simple example). Then
create
src/main/resources/META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider,
which contains the names of your custom dialects, one per line like so:

com.axiomalaska.dialects.CustomSQLServerSpatialDialect
com.axiomalaska.dialects.CustomOracle10gSpatialDialect

Everything should work after that, and you should be able to switch dialects
just by changing one line in hibernate-spatial.cfg.xml

-Shane

On Thu, Mar 31, 2011 at 4:19 PM, shane <[hidden email]> wrote:

> I'm running into this problem, and attacked it without much initial
> success.
> I was also expecting HS to use the dialect configured in the hibernate
> configuration.
>
> I attempted to use the hibernate-spatial.cfg.xml solution proposed by Juan,
> but then HBSpatialExtention.createSpatialDialect started complaining: "No
> SpatialDialect provider for persistenceUnit com.blah.blah.CustomDialect."
>
> I then created the
> META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider file in
> my
> application and listed my two custom dialects on two lines. Still no luck.
>
> Any advice on how to do this? I'll dig into the source again soon, but any
> pointers would be appreciated. Is there any reason that HS doesn't just use
> the dialect indicated by the Hibernate config?
>
> --
> View this message in context:
> http://hibernate-spatial.1140993.n2.nabble.com/Having-both-hibernate-spatial-oracle-and-hibernate-spatial-postgres-jar-files-in-the-classpath-tp5338414p6229025.html
> Sent from the Hibernate Spatial - Users mailing list archive at Nabble.com.
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
>
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>



--
Shane StClair
Software Engineer
Axiom Consulting & Design
523 W 8th Ave
Suite 104
Anchorage, AK 99501
http://www.axiomalaska.com

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