Quantcast

Need help tweaking BasicDataSource in Grails 1.0.3.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Need help tweaking BasicDataSource in Grails 1.0.3.

jondo_w
The next version of our product will be launched with Grails v1.3.5 but until then I'm stuck at Grails 1.0.3. and it's lack of support for configuration of the DataSource. Specifically I'm referring to the ability to set properties like initialSize, maxIdle etc. straight from the DataSource.groovy file.

So to try and get around this, I turned to the resources.groovy file and configured my DataSource as follows:

beans = {
    dataSource(BasicDataSource) {
        driverClassName = CH.config.dataSource.driverClassName
        url = CH.config.dataSource.url
        username = CH.config.dataSource.username
        password = CH.config.dataSource.password
        maxActive = 30
        maxIdle = 15
        minIdle = 10
        initialSize = 10
    }
    sessionFactory(ConfigurableLocalSessionFactoryBean) {
        def props = [:]
        if (CH.config.dataSource.dbCreate) {
            props["hibernate.hbm2ddl.auto"] = CH.config.dataSource.dbCreate
        }
        if (CH.config.dataSource.show_sql) {
            props["hibernate.show_sql"] = CH.config.dataSource.show_sql
        }
        if (CH.config.dataSource.dialect) {
            props["hibernate.dialect"] = CH.config.dataSource.dialect
        }
        hibernateProperties = props
    }
}

This works insofar as the DataSource seems to be correctly initialised, and I see 10 connections made to the DB in the DB mgt client. However as soon as my Grails app reaches any reference to a domain class during startup, it throws the following error:

Caused by: org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: AuthRole; nested exception is org.hibernate.MappingException: Unknown entity: AuthRole
    at AuthBootStrap$_addNewRoles_closure3.doCall(AuthBootStrap.groovy:39)
    at AuthBootStrap.addNewRoles(AuthBootStrap.groovy:35)
    at AuthBootStrap$_closure1.doCall(AuthBootStrap.groovy:13)
    ... 12 more

AuthRole being a domain class used in a simple authentication framework we developed as part of our product. This is effectively the first time a domain class is referenced during startup.

How has my above configuration of the Spring beans in resources.groovy broken the GORM tie-in to Spring/Hibernate? Is there anything I can do to fix that?

Thanks,
Darryl Pentz



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help tweaking BasicDataSource in Grails 1.0.3. - FIXED

jondo_w
For anybody who might want to do this in future, the fix for this was very simple. I didn't need the 'sessionFactory' block in the resources.groovy.


From: Darryl Pentz <[hidden email]>
To: [hidden email]
Sent: Thu, December 9, 2010 11:28:02 PM
Subject: [grails-user] Need help tweaking BasicDataSource in Grails 1.0.3.

The next version of our product will be launched with Grails v1.3.5 but until then I'm stuck at Grails 1.0.3. and it's lack of support for configuration of the DataSource. Specifically I'm referring to the ability to set properties like initialSize, maxIdle etc. straight from the DataSource.groovy file.

So to try and get around this, I turned to the resources.groovy file and configured my DataSource as follows:

beans = {
    dataSource(BasicDataSource) {
        driverClassName = CH.config.dataSource.driverClassName
        url = CH.config.dataSource.url
        username = CH.config.dataSource.username
        password = CH.config.dataSource.password
        maxActive = 30
        maxIdle = 15
        minIdle = 10
        initialSize = 10
    }
    sessionFactory(ConfigurableLocalSessionFactoryBean) {
        def props = [:]
        if (CH.config.dataSource.dbCreate) {
            props["hibernate.hbm2ddl.auto"] = CH.config.dataSource.dbCreate
        }
        if (CH.config.dataSource.show_sql) {
            props["hibernate.show_sql"] = CH.config.dataSource.show_sql
        }
        if (CH.config.dataSource.dialect) {
            props["hibernate.dialect"] = CH.config.dataSource.dialect
        }
        hibernateProperties = props
    }
}

This works insofar as the DataSource seems to be correctly initialised, and I see 10 connections made to the DB in the DB mgt client. However as soon as my Grails app reaches any reference to a domain class during startup, it throws the following error:

Caused by: org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: AuthRole; nested exception is org.hibernate.MappingException: Unknown entity: AuthRole
    at AuthBootStrap$_addNewRoles_closure3.doCall(AuthBootStrap.groovy:39)
    at AuthBootStrap.addNewRoles(AuthBootStrap.groovy:35)
    at AuthBootStrap$_closure1.doCall(AuthBootStrap.groovy:13)
    ... 12 more

AuthRole being a domain class used in a simple authentication framework we developed as part of our product. This is effectively the first time a domain class is referenced during startup.

How has my above configuration of the Spring beans in resources.groovy broken the GORM tie-in to Spring/Hibernate? Is there anything I can do to fix that?

Thanks,
Darryl Pentz




Loading...