alexkramer / grails-hibernate-filter

Hibernate Filters Support for Grails 3, Hibernate 5, and GORM 6
Apache License 2.0
4 stars 8 forks source link

Grails custom data source properties are not set when injecting the datasource in a service #12

Open gabivis opened 4 years ago

gabivis commented 4 years ago

Steps to Reproduce define a dataSource in application.groovy (I use tomcat jdbc connection pooling) dataSource { pooled= true username = password = ... properties { ... maxActive=16 testOnBorrow=true testWhileIdle=true
} } Reference the dataSource in a service class MyService { def dataSource def myMethod() { def sql = new Sql(dataSource) ... } } Expected Behaviour The datasource has the same custom properties as the ones set in application.groovy: i.e. testOnBorrow=true, testWhileIdle=true

Actual Behaviour The properties inside the properties block are ignored and so testOnBorrow=false, testWhileIdle=false

Environment Information Grails Version: 3.3.9 JDK Version: 1.8 Container Version (If Applicable): Tomcat

vsachinv commented 2 years ago

@gabivis Did you find any solution for the same out of the box ?

vsachinv commented 2 years ago

@gabivis As work around we have overridden bean like below in project resources.groovy.

  def domainClasses = grailsApplication.getArtefacts(DomainClassArtefactHandler.TYPE)
            .findAll { it.mappingStrategy != "none" && it.mappingStrategy == GrailsDomainClass.GORM }
            .collect { it.getClazz() }

    hibernateConnectionSourceFactory(HibernateFilterConnectionSourceFactory, domainClasses as Class[]) {
        dataSourceConnectionSourceFactory = ref('dataSourceConnectionSourceFactory')
    }

to avoid recreation of another dataSourceConnectionSourceFactory.