1

I keep getting this error at the end of a test-app.

Error Error executing script TestApp: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '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 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException: Driver:org.postgresql.Driver@997931c returned null for URL:jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000 (Use --stacktrace to see the full trace)

I'm trying to upgrade from 2.1.0 to 2.3.7. run-app works fine, but the test-app keeps breaking. This is what my dataSource.groovy looks like.

dataSource {
    pooled = true
    driverClassName = "org.postgresql.Driver"
    dialect="org.hibernate.dialect.PostgreSQLDialect"
    username = "username"
    password = "password"
}

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
//            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:postgresql://localhost/mydb"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
        }
    }
    /*production {
        dataSource {
//            dbCreate = "update"
            url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }
    }*/
}

I have this in my BuildConfig.groovy under the dependencies section.

runtime "org.postgresql:postgresql:9.3-1100-jdbc4"

Been at it since yesterday. It used to work in 2.1.0. I have around 200+ tests around 50% of it failed and at the end of failed message is that error. Help?

zeitgeist
  • 13
  • 4

3 Answers3

0

Try to switch this one :

dataSource {
    pooled = true
    driverClassName = "org.postgresql.Driver"
    dialect="org.hibernate.dialect.PostgreSQLDialect"
    username = "username"
    password = "password"
}

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
//            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:postgresql://localhost/mydb"
        }
    }
    test {
        dataSource { 
        driverClassName = "org.h2.Driver"
        username = "sa"
        password = ""
        pooled = true
        dbCreate = "update"
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
        }
    }
    /*production {
        }
     */
  }
Develop4Life
  • 7,581
  • 8
  • 58
  • 76
0

Your url for test is a h2 database, so you should move:

driverClassName = "org.postgresql.Driver"
dialect="org.hibernate.dialect.PostgreSQLDialect"

to your development datasource and add

driverClassName = "org.h2.Driver"

to your test datasource.

Michael Legart
  • 800
  • 4
  • 7
0

I think you are using the wrong driver for an h2 database. Try with:

test {
    dataSource {
        driverClassName = "org.h2.Driver"
        dbCreate = "update"
        url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
    }
}
Fran García
  • 2,011
  • 16
  • 24
  • Seriously? I've been running test-app all this time using the same datasource in 2.1.0 and it never gave me that. Anyway, I'm worried if I used a different driver, how will that affect my tests? Like, I know mysql and postgres are same in principle but probably got some minor differences. I just wanna test on an environment that is much closer to psql because that's what is on prod right now (I didn't include it in my code above). – zeitgeist Apr 23 '14 at 08:13
  • Of course, I would suggest you to use also a postgresql database in your test environment url = "jdbc:postgresql://localhost/mydb4test" – Fran García Apr 23 '14 at 08:56