Hi,
I am trying to implement oracle vpd in my grails 1.0.5 app and came across this thread. I tried the solution proved by burt but getting an error. I get this error below while starting the app. I am using datasources plugin to access more than one schema. The two classes are exactly same as from the link except they are in different package. I would really appreciate any help.
top of DataSource.groovy:
dataSource {
configClass="com.bwse.vpd.MyHibernateConfiguration"
pooled = true
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'messageSource': Initialization of bean failed; nested exception is org.s
pringframework.beans.factory.BeanCreationException: Error creating bean with nam
e 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while
setting bean property 'sessionFactory'; nested exception is org.springframework.
beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto
ry': Invocation of init method failed; nested exception is org.hibernate.Hiberna
teException: JDBC URL was not specified by property hibernate.connection.url
at java.security.AccessController.doPrivileged(Native Method)
at RunApp_groovy$_run_closure2_closure7.doCall(RunApp_groovy:69)
at RunApp_groovy$_run_closure2_closure7.doCall(RunApp_groovy)
at Init_groovy$_run_closure6.doCall(Init_groovy:131)
at RunApp_groovy$_run_closure2.doCall(RunApp_groovy:68)
at RunApp_groovy$_run_closure2.doCall(RunApp_groovy)
at RunApp_groovy$_run_closure1.doCall(RunApp_groovy:59)
at RunApp_groovy$_run_closure1.doCall(RunApp_groovy)
at gant.Gant.dispatch(Gant.groovy:271)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:436)
at gant.Gant.processArgs(Gant.groovy:372)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name 'transactionManager': Cannot resolve reference to bean 'sessio
nFactory' while setting bean property 'sessionFactory'; nested exception is org.
springframework.beans.factory.BeanCreationException: Error creating bean with na
me 'sessionFactory': Invocation of init method failed; nested exception is org.h
ibernate.HibernateException: JDBC URL was not specified by property hibernate.co
nnection.url
at java.security.AccessController.doPrivileged(Native Method)
... 13 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name 'sessionFactory': Invocation of init method failed; nested exc
eption is org.hibernate.HibernateException: JDBC URL was not specified by proper
ty hibernate.connection.url
at java.security.AccessController.doPrivileged(Native Method)
... 14 more
Caused by: org.hibernate.HibernateException: JDBC URL was not specified by prope
rty hibernate.connection.url
at com.bwse.vpd.MyHibernateConfiguration.buildSettings(MyHibernateConfig
uration.java:16)
... 15 more
Burt Beckwith wrote
I googled a bit and found this:
http://javazone.org/howto/hibernate-with-oracle-vpdHe suggests using a hibernate.cfg.xml, but you're just setting a Hibernate property, so you could just put it in hibernate.properties in a regular Hibernate app. In Grails, you should be able to put it in the 'hibernate' block in DataSource.groovy, e.g.
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
connection.provider_class='org.javazone.hibernate.MyConnectionProvider'
...
}
I tried this and it didn't work - it sets the property correctly but then ConfigurableLocalSessionFactoryBean overrides the value, setting it to 'org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider'. There might be a simpler fix, but I was able to get it working by subclassing the Grails Configuration class:
package com.foo.bar.MyHibernateConfiguration;
import org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration;
import org.hibernate.cfg.Settings;
public class MyHibernateConfiguration extends DefaultGrailsDomainConfiguration {
@Override
public Settings buildSettings(final Properties props) {
props.setProperty("hibernate.connection.provider_class", "org.javazone.hibernate.MyConnectionProvider");
return super.buildSettings(props);
}
}
Set the 'configClass' property in DataSource.groovy to use the custom subclass:
dataSource {
configClass = com.foo.bar.MyHibernateConfiguration
pooled = true
...
}
Once I did this, I got a ClassNotFoundException as expected since I don't have a org.javazone.hibernate.MyConnectionProvider in my classpath.
Note that Configuration subclasses have to be written in Jave due to Groovy weirdness.
--
Burt
On Monday 29 December 2008 4:25:26 pm aaron remick wrote:
> I realize my inital question was a bit vauge, I'll be more specific:
>
> In Grails, how would I define my own DriverManagerConnectionProvider for
> hibernate? I know how to write the class, I'm assuming that I'd change it in
> DataSource.groovy, but I don't know the syntax.
>
> Any help?
>
> aaron
>
> On Sat, Dec 27, 2008 at 9:04 PM, aaron remick <aaron@remick.net> wrote:
>
> > Hello,
> >
> > Anyone have any experience/advise on building a grails app against an
> > Oracle database using VPD? Essentially it requires setting an Oracle
> > "context" for the connection prior to working with persisted objects. I've
> > found some helpful info on Hibernate/VPD, but am not quite sure how to best
> > implement in grails.
> >
> > Thanks,
> >
> > --
> > remick
> >
> >
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email