Choosing Dialect with hibernate.cfg.xml ?

6 messages Options Options
Embed this Post
Permalink
Haavard N

Choosing Dialect with hibernate.cfg.xml ?

Reply Threaded MoreMore options
Print post
Permalink
Hi all!


I have a small problem with the new configuration-system in v1.0-M1. My goal is to use the same POM for either Oracle (production) or PostgreSQL (test). Including both hibernate-spatial-oracle and hibernate-spatial-postgis will lead to that the Oracle dialect is always chosen - even though i specify that I want to use org.hibernatespatial.postgis.PostgisDialect in the hibernate.cfg.xml.

I checked out the code from SVN, and pinpointed the problem to the HBSpatialExtension class (where the selection of dialect occures). Seems like if there's no DefaultDialect set as a system property, the first dialect it can find through the classloader will be used. This is kind of OK, but I'd really like to determine what dialect to use from the hibernate.cfg.xml using the "hibernate.dialect" property (or something similar to that). I haven't looked through ALL of the Hibernate Spatial code, but as far as I can see there's no way that it will be controlled by the hibernate.cfg.xml configuration.


Best regards,

Håvard N.
_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@...
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: Choosing Dialect with hibernate.cfg.xml ?

Reply Threaded MoreMore options
Print post
Permalink
Hi,

First, you're correct in that the HBSpatialExtension doesn't  
automatically use the configuration file to determine the spatial  
dialect.  Secondly, the configuration system isn't completely  
finished, and some issues are not settled.

It is possible, however, to ensure that the correct spatial dialect  
is determined from the hibernate.dialect property. In start-up code  
(HibernateUtil, or some such) you should add the following code:

// configure Hibernate
Configuration hbConfig = new Configuration();
hbConfig.configure();

//configure Hibernate Spatial
HSConfiguration hsConfig = new HSConfiguration();
//inspect the hibernate.dialect  from the Hibernate Configuration.
hsConfig.configure(hbConfig);
//... and set HBSpatialExtension to this configuration
HBSpatialExtension.setConfiguration(hsConfig);

Let me know if this works.

Regards,

Karel Maesen


On 20 May 2008, at 09:58, havard.nesse@... wrote:

> Hi all!
>
>
> I have a small problem with the new configuration-system in v1.0-
> M1. My goal is to use the same POM for either Oracle (production)  
> or PostgreSQL (test). Including both hibernate-spatial-oracle and  
> hibernate-spatial-postgis will lead to that the Oracle dialect is  
> always chosen - even though i specify that I want to use  
> org.hibernatespatial.postgis.PostgisDialect in the hibernate.cfg.xml.
>
> I checked out the code from SVN, and pinpointed the problem to the  
> HBSpatialExtension class (where the selection of dialect occures).  
> Seems like if there's no DefaultDialect set as a system property,  
> the first dialect it can find through the classloader will be used.  
> This is kind of OK, but I'd really like to determine what dialect  
> to use from the hibernate.cfg.xml using the "hibernate.dialect"  
> property (or something similar to that). I haven't looked through  
> ALL of the Hibernate Spatial code, but as far as I can see there's  
> no way that it will be controlled by the hibernate.cfg.xml  
> configuration.
>
>
> Best regards,
>
> Håvard N.
> _______________________________________________
> hibernatespatial-users mailing list
> hibernatespatial-users@...
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@...
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Haavard N

Re: Choosing Dialect with hibernate.cfg.xml ?

Reply Threaded MoreMore options
Print post
Permalink
Hello again!

It seems like your solution works as you've described. I was able to choose dialect by changing it in the hibernate.cfg.xml, but this isn't the end of my problems. The project I'm working on is a Spring project, and all configuration is put in the applicationContext.xml file - including the Hibernate configuration. The properties bean looks something like:

<bean id="hibernateProperties"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="properties">
                <props>
                        <prop key="hibernate.default-lazy">false</prop>
                        <prop key="hibernate.show_sql">true</prop>
                        <prop key="hibernate.hbm2ddl.auto">update</prop>
                        <prop key="hibernate.dialect">org.hibernatespatial.postgis.PostgisDialect</prop>
                        <prop key="hibernate.cache.use_second_level_cache">false</prop>
                        <prop key="hibernate.cache.use_query_cache">false</prop>
                </props>
        </property>
</bean>

The code snipplet you submitted will have to be run somewhere (and before Hibernate gets initialized by Spring), but I've had a hard time trying to figure out where to put it, and how I can make Spring execute it before Hibernate is initialized.

I also have another question:
I've implemented the within()-search using Criterion. But is there an "nearest neighbour"-search?


Regards,

Håvard N

Karel Maesen wrote:
Hi,

First, you're correct in that the HBSpatialExtension doesn't  
automatically use the configuration file to determine the spatial  
dialect.  Secondly, the configuration system isn't completely  
finished, and some issues are not settled.

It is possible, however, to ensure that the correct spatial dialect  
is determined from the hibernate.dialect property. In start-up code  
(HibernateUtil, or some such) you should add the following code:

// configure Hibernate
Configuration hbConfig = new Configuration();
hbConfig.configure();

//configure Hibernate Spatial
HSConfiguration hsConfig = new HSConfiguration();
//inspect the hibernate.dialect  from the Hibernate Configuration.
hsConfig.configure(hbConfig);
//... and set HBSpatialExtension to this configuration
HBSpatialExtension.setConfiguration(hsConfig);

Let me know if this works.

Regards,

Karel Maesen
_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@lists.hibernatespatial.org
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: Choosing Dialect with hibernate.cfg.xml ?

Reply Threaded MoreMore options
Print post
Permalink
Hi Håvard,

I guess the best solution would be to always check and load the  
hibernate-spatial.cfg.xml when the extension loads into memory (in  
the static initializer).

Can you make that change? Otherwise I'll try to make the modification  
and commit it to SVN  next week.

A nearest-neighbor search is not specified by the OGC SFS  
specification on which Hibernate Spatial is based. For Oracle,  
however, the SDO_NN nearest-neighbo operator is available in the  
OracleSpatialRestrictions factory class. So if you're using Oracle,  
you're in luck. For postgis, these types of operators still need to  
be implemented.

Regards,


Karel


On 05 Jun 2008, at 10:06, Haavard N wrote:

>
> Hello again!
>
> It seems like your solution works as you've described. I was able  
> to choose
> dialect by changing it in the hibernate.cfg.xml, but this isn't the  
> end of
> my problems. The project I'm working on is a Spring project, and all
> configuration is put in the applicationContext.xml file - including  
> the
> Hibernate configuration. The properties bean looks something like:
>
> <bean id="hibernateProperties"
>
> class="org.springframework.beans.factory.config.PropertiesFactoryBean"
> >
> <property name="properties">
> <props>
> <prop key="hibernate.default-lazy">false</prop>
> <prop key="hibernate.show_sql">true</prop>
> <prop key="hibernate.hbm2ddl.auto">update</prop>
> <prop
> key="hibernate.dialect">org.hibernatespatial.postgis.PostgisDialect</p
> rop>
> <prop key="hibernate.cache.use_second_level_cache">false</prop>
> <prop key="hibernate.cache.use_query_cache">false</prop>
> </props>
> </property>
> </bean>
>
> The code snipplet you submitted will have to be run somewhere (and  
> before
> Hibernate gets initialized by Spring), but I've had a hard time  
> trying to
> figure out where to put it, and how I can make Spring execute it  
> before
> Hibernate is initialized.
>
> I also have another question:
> I've implemented the within()-search using Criterion. But is there an
> "nearest neighbour"-search?
>
>
> Regards,
>
> Håvard N
>
>
> Karel Maesen wrote:
>>
>> Hi,
>>
>> First, you're correct in that the HBSpatialExtension doesn't
>> automatically use the configuration file to determine the spatial
>> dialect.  Secondly, the configuration system isn't completely
>> finished, and some issues are not settled.
>>
>> It is possible, however, to ensure that the correct spatial dialect
>> is determined from the hibernate.dialect property. In start-up code
>> (HibernateUtil, or some such) you should add the following code:
>>
>> // configure Hibernate
>> Configuration hbConfig = new Configuration();
>> hbConfig.configure();
>>
>> //configure Hibernate Spatial
>> HSConfiguration hsConfig = new HSConfiguration();
>> //inspect the hibernate.dialect  from the Hibernate Configuration.
>> hsConfig.configure(hbConfig);
>> //... and set HBSpatialExtension to this configuration
>> HBSpatialExtension.setConfiguration(hsConfig);
>>
>> Let me know if this works.
>>
>> Regards,
>>
>> Karel Maesen
>> _______________________________________________
>> hibernatespatial-users mailing list
>> hibernatespatial-users@...
>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
>> hibernatespatial-users
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Choosing- 
> Dialect-with-hibernate.cfg.xml---tp17335222p17664393.html
> Sent from the Hibernate Spatial - Users mailing list archive at  
> Nabble.com.
>
> _______________________________________________
> hibernatespatial-users mailing list
> hibernatespatial-users@...
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@...
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Haavard N

Re: Choosing Dialect with hibernate.cfg.xml ?

Reply Threaded MoreMore options
Print post
Permalink
Hi!

I've fixed this by adding the following lines in HBSpatialExtension (in the static block right before the "String dialectProp = System.getProperty(DIALECT_PROP_NAME);:" line.

HSConfiguration hsConfig = new HSConfiguration();

// Defaults to "hibernate-spatial.cfg.xml"
hsConfig.configure();
               
// Check for null as this will lead to a NullpointerException in setConfiguration()
if(hsConfig!=null) {
        setConfiguration(hsConfig);
}


This seems to fix this issue for us, but I'm not sure if this change will break something else :) (this might be outside the scope of the unit tests).

I guess we're in luck since we're "converting" to Oracle now (I might try to implement this nearest neighbor search for PostGIS as well - if I do I will of course send you the code.)


- Håvard


Karel Maesen wrote:
Hi Håvard,

I guess the best solution would be to always check and load the  
hibernate-spatial.cfg.xml when the extension loads into memory (in  
the static initializer).

Can you make that change? Otherwise I'll try to make the modification  
and commit it to SVN  next week.

A nearest-neighbor search is not specified by the OGC SFS  
specification on which Hibernate Spatial is based. For Oracle,  
however, the SDO_NN nearest-neighbo operator is available in the  
OracleSpatialRestrictions factory class. So if you're using Oracle,  
you're in luck. For postgis, these types of operators still need to  
be implemented.

Regards,


Karel
Karel Maesen

Re: Choosing Dialect with hibernate.cfg.xml ?

Reply Threaded MoreMore options
Print post
Permalink
Hi Håvard,

Thanks for the update. I'm confident that your modification won't  
cause problems. Probably I'm going to incorporate this in the code  
base also.

As always any contribution is welcome.

Regards,

Karel Maesen


On 16 Jun 2008, at 13:32, Haavard N wrote:

>
> Hi!
>
> I've fixed this by adding the following lines in HBSpatialExtension  
> (in the
> static block right before the "String dialectProp =
> System.getProperty(DIALECT_PROP_NAME);:" line.
>
> HSConfiguration hsConfig = new HSConfiguration();
>
> // Defaults to "hibernate-spatial.cfg.xml"
> hsConfig.configure();
>
> // Check for null as this will lead to a NullpointerException in
> setConfiguration()
> if(hsConfig!=null) {
> setConfiguration(hsConfig);
> }
>
>
> This seems to fix this issue for us, but I'm not sure if this  
> change will
> break something else :) (this might be outside the scope of the  
> unit tests).
>
> I guess we're in luck since we're "converting" to Oracle now (I  
> might try to
> implement this nearest neighbor search for PostGIS as well - if I  
> do I will
> of course send you the code.)
>
>
> - Håvard
>
>
>
> Karel Maesen wrote:
>>
>> Hi Håvard,
>>
>> I guess the best solution would be to always check and load the
>> hibernate-spatial.cfg.xml when the extension loads into memory (in
>> the static initializer).
>>
>> Can you make that change? Otherwise I'll try to make the modification
>> and commit it to SVN  next week.
>>
>> A nearest-neighbor search is not specified by the OGC SFS
>> specification on which Hibernate Spatial is based. For Oracle,
>> however, the SDO_NN nearest-neighbo operator is available in the
>> OracleSpatialRestrictions factory class. So if you're using Oracle,
>> you're in luck. For postgis, these types of operators still need to
>> be implemented.
>>
>> Regards,
>>
>>
>> Karel
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Choosing- 
> Dialect-with-hibernate.cfg.xml---tp17335222p17862363.html
> Sent from the Hibernate Spatial - Users mailing list archive at  
> Nabble.com.
>
> _______________________________________________
> hibernatespatial-users mailing list
> hibernatespatial-users@...
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@...
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users