4

Summary

I'm trying to create a new grails 3.3.0 application, with some simple domain classes.

I'm also using the new HibernateSpec (coming with GORM 6.1.x) to create an in-memory H2 database for my unit test.

I used this technique with previous versions of grails, but now with grails 3.3.0 I am getting a system failure.

Hibernate seems to create the tables, but then, when I try to execute a query inside my unit test, it complains that the table cannot be found.

Details

This is my datasource configuration (in application.groovy):

dataSource {
    pooled = true
    jmxExport = true
    driverClassName = "org.h2.Driver"
    username = "sa"
    password = ""
    logSql = true
}


environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false"
        }
    }
    test {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false"
        }
    }
}

Ehcache is disabled (application.yml)

hibernate:
    cache:
        queries: false
        use_second_level_cache: false
        use_query_cache: false

My Domain class

class Application {
    String name

    static constraints = {
        name unique: true, nullable: false, blank: false, maxSize: 40
    }

}

Other domain classes

Typical SecUser, SecRole, SecUserSecRole generated by spring-security-core.

Unit test

import grails.testing.services.ServiceUnitTest
import org.apache.commons.lang.RandomStringUtils

class ApplicationDetailsServiceSpec extends HibernateSpec implements ServiceUnitTest<ApplicationDetailsService> {
    private APP_NAME = anyString()
    List<Class> getDomainClasses() { [Application, SecRole, AppRole, SecUser, SecUserSecRole] }

    def setup() {
        new Application(name: APP_NAME).save(failOnError: true, flush: true)
    }

    def cleanup() {
    }

    def "It filters authorities through the set of a given application's declared roles"() {
        expect:
        true
    }

    String anyString(int size = 10) {
        RandomStringUtils.randomAlphanumeric(size)
    }

}

Output and failure

I have enabled org.hibernate tracing in logback.groovy to see what hibernate is up to behind the scenes, and I can see the DDL being (apparently) executed:

2017-08-08 18:23:21.763 TRACE --- [           main] o.h.s.i.AbstractServiceRegistryImpl      : Initializing service [role=org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractor]
2017-08-08 18:23:21.765 DEBUG --- [           main] org.hibernate.SQL                        : drop table app_role if exists
2017-08-08 18:23:21.767 DEBUG --- [           main] org.hibernate.SQL                        : drop table application if exists
2017-08-08 18:23:21.768 DEBUG --- [           main] org.hibernate.SQL                        : drop table sec_role if exists
2017-08-08 18:23:21.768 DEBUG --- [           main] org.hibernate.SQL                        : drop table sec_user if exists
2017-08-08 18:23:21.768 DEBUG --- [           main] org.hibernate.SQL                        : drop table sec_user_sec_role if exists
2017-08-08 18:23:21.771 DEBUG --- [           main] org.hibernate.SQL                        : create table app_role (id bigint generated by default as identity, version bigint not null, role_id bigint not null, application_id bigint not null, primary key (id))
2017-08-08 18:23:21.781 DEBUG --- [           main] org.hibernate.SQL                        : create table application (id bigint generated by default as identity, version bigint not null, name varchar(40) not null, primary key (id))
2017-08-08 18:23:21.783 DEBUG --- [           main] org.hibernate.SQL                        : create table sec_role (id bigint generated by default as identity, version bigint not null, authority varchar(255) not null, primary key (id))
2017-08-08 18:23:21.785 DEBUG --- [           main] org.hibernate.SQL                        : create table sec_user (id bigint generated by default as identity, version bigint not null, password_expired boolean not null, username varchar(80) not null, account_locked boolean not null, passwd varchar(255) not null, account_expired boolean not null, enabled boolean default true not null, domain varchar(20) not null, primary key (id))
2017-08-08 18:23:21.786 DEBUG --- [           main] org.hibernate.SQL                        : create table sec_user_sec_role (sec_role_id bigint not null, sec_user_id bigint not null, primary key (sec_role_id, sec_user_id))
2017-08-08 18:23:21.790 DEBUG --- [           main] org.hibernate.SQL                        : alter table app_role add constraint UK959dd00167bfcc85a258e2ef8ac2 unique (application_id, role_id)
2017-08-08 18:23:21.792 DEBUG --- [           main] org.hibernate.SQL                        : alter table application add constraint UK_lspnba25gpku3nx3oecprrx8c unique (name)
2017-08-08 18:23:21.793 DEBUG --- [           main] org.hibernate.SQL                        : alter table sec_role add constraint UK_oah023x2ltqw09mdue7w0mcxb unique (authority)
2017-08-08 18:23:21.793 DEBUG --- [           main] org.hibernate.SQL                        : alter table sec_user add constraint UK_5ctbdrlf3eismye20vsdtk8w8 unique (username)
2017-08-08 18:23:21.794 DEBUG --- [           main] org.hibernate.SQL                        : alter table app_role add constraint FK6ai2jr980ml7dc9qqvxqw7gu3 foreign key (role_id) references sec_role
2017-08-08 18:23:21.799 DEBUG --- [           main] org.hibernate.SQL                        : alter table app_role add constraint FKcef54852fqjq1f3lfshkl3d25 foreign key (application_id) references application
2017-08-08 18:23:21.800 DEBUG --- [           main] org.hibernate.SQL                        : alter table sec_user_sec_role add constraint FKf4m8563aw7lu33q9g25hf1kaf foreign key (sec_role_id) references sec_role
2017-08-08 18:23:21.802 DEBUG --- [           main] org.hibernate.SQL                        : alter table sec_user_sec_role add constraint FK81r3vb2e9li23kwl9ykbo2l05 foreign key (sec_user_id) references sec_user
2017-08-08 18:23:21.805  INFO --- [           main] o.h.t.schema.internal.SchemaCreatorImpl  : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@5f8f1712'
2017-08-08 18:23:21.808 DEBUG --- [           main] o.h.internal.NamedQueryRepository        : Checking 0 named HQL queries
2017-08-08 18:23:21.808 DEBUG --- [           main] o.h.internal.NamedQueryRepository        : Checking 0 named SQL queries
2017-08-08 18:23:21.809 DEBUG --- [           main] o.h.internal.SessionFactoryRegistry      : Initializing SessionFactoryRegistry : org.hibernate.internal.SessionFactoryRegistry@6f1fa1d0
2017-08-08 18:23:21.809 DEBUG --- [           main] o.h.internal.SessionFactoryRegistry      : Registering SessionFactory: b4cf540a-2e5b-40fd-bae8-7ca026575a35 (<unnamed>)
2017-08-08 18:23:21.809 DEBUG --- [           main] o.h.internal.SessionFactoryRegistry      : Not binding SessionFactory to JNDI, no JNDI name configured
2017-08-08 18:23:21.856 DEBUG --- [           main] o.h.v.i.e.r.DefaultTraversableResolver   : Found javax.persistence.Persistence on classpath containing 'getPersistenceUtil'. Assuming JPA 2 environment. Trying to instantiate JPA aware TraversableResolver
2017-08-08 18:23:21.856 DEBUG --- [           main] o.h.v.i.e.r.DefaultTraversableResolver   : Instantiated JPA aware TraversableResolver of type org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.
2017-08-08 18:23:21.856 DEBUG --- [           main] o.h.v.internal.engine.ConfigurationImpl  : Setting custom TraversableResolver of type org.grails.datastore.gorm.validation.javax.MappingContextTraversableResolver
2017-08-08 18:23:21.856 DEBUG --- [           main] o.h.v.internal.engine.ConfigurationImpl  : Setting custom MessageInterpolator of type org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator
2017-08-08 18:23:21.856  INFO --- [           main] o.h.v.internal.engine.ConfigurationImpl  : HV000002: Ignoring XML configuration.



2017-08-08 18:23:22.212 TRACE --- [           main] .i.SessionFactoryImpl$SessionBuilderImpl : Opening Hibernate Session.  tenant=null, owner=null
2017-08-08 18:23:22.245 TRACE --- [           main] o.h.s.i.AbstractServiceRegistryImpl      : Initializing service [role=org.hibernate.stat.spi.StatisticsImplementor]
2017-08-08 18:23:22.249 DEBUG --- [           main] o.h.stat.internal.StatisticsInitiator    : Statistics initialized [enabled=false]
2017-08-08 18:23:22.249 TRACE --- [           main] org.hibernate.internal.SessionImpl       : Opened session at timestamp: 15022094022
2017-08-08 18:23:22.251 DEBUG --- [           main] o.h.e.t.internal.TransactionImpl         : begin
2017-08-08 18:23:22.251 TRACE --- [           main] j.i.AbstractLogicalConnectionImplementor : Preparing to begin transaction via JDBC Connection.setAutoCommit(false)
2017-08-08 18:23:22.251 TRACE --- [           main] j.i.AbstractLogicalConnectionImplementor : Transaction begun via JDBC Connection.setAutoCommit(false)
2017-08-08 18:23:22.251 TRACE --- [           main] cResourceLocalTransactionCoordinatorImpl : ResourceLocalTransactionCoordinatorImpl#afterBeginCallback
2017-08-08 18:23:22.253 TRACE --- [           main] org.hibernate.internal.SessionImpl       : Setting flush mode to: COMMIT
2017-08-08 18:23:22.476 DEBUG --- [           main] org.hibernate.SQL                        : select this_.id as y0_ from application this_ where this_.name=? limit ?
2017-08-08 18:23:22.483 DEBUG --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : could not prepare statement [select this_.id as y0_ from application this_ where this_.name=? limit ?]

org.h2.jdbc.JdbcSQLException: Table "APPLICATION" not found; SQL statement:
select this_.id as y0_ from application this_ where this_.name=? limit ? [42102-195]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:179)
    at org.h2.message.DbException.get(DbException.java:155)
    at org.h2.command.Parser.readTableOrView(Parser.java:5506)
    at org.h2.command.Parser.readTableFilter(Parser.java:1260)
    at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1940)
    at org.h2.command.Parser.parseSelectSimple(Parser.java:2089)
    at org.h2.command.Parser.parseSelectSub(Parser.java:1934)
    at org.h2.command.Parser.parseSelectUnion(Parser.java:1749)
    at org.h2.command.Parser.parseSelect(Parser.java:1737)
    at org.h2.command.Parser.parsePrepared(Parser.java:448)
    at org.h2.command.Parser.parse(Parser.java:320)
    at org.h2.command.Parser.parse(Parser.java:292)
    at org.h2.command.Parser.prepareCommand(Parser.java:257)
    at org.h2.engine.Session.prepareLocal(Session.java:573)
    at org.h2.engine.Session.prepareCommand(Session.java:514)
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1204)
    at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:73)
    at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:288)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy$LazyConnectionInvocationHandler.invoke(LazyConnectionDataSourceProxy.java:376)
    at com.sun.proxy.$Proxy36.prepareStatement(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:240)
    at com.sun.proxy.$Proxy36.prepareStatement(Unknown Source)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1934)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1903)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1881)
    at org.hibernate.loader.Loader.doQuery(Loader.java:925)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
    at org.hibernate.loader.Loader.doList(Loader.java:2622)
    at org.hibernate.loader.Loader.doList(Loader.java:2605)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2434)
    at org.hibernate.loader.Loader.list(Loader.java:2429)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1787)
    at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
    at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResultViaListCall(AbstractHibernateQuery.java:801)
    at org.grails.orm.hibernate.query.AbstractHibernateQuery.singleResult(AbstractHibernateQuery.java:791)
    at grails.gorm.DetachedCriteria$_get_closure1.doCall(DetachedCriteria.groovy:115)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
    at groovy.lang.Closure.call(Closure.java:414)
    at groovy.lang.Closure.call(Closure.java:430)
    at grails.gorm.DetachedCriteria$_withPopulatedQuery_closure8.doCall(DetachedCriteria.groovy:766)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
    at groovy.lang.Closure.call(Closure.java:414)
    at groovy.lang.Closure.call(Closure.java:430)
    at org.grails.datastore.gorm.GormStaticApi$_withDatastoreSession_closure22.doCall(GormStaticApi.groovy:836)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
    at groovy.lang.Closure.call(Closure.java:414)
    at org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:54)
    at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:124)
    at com.sun.proxy.$Proxy38.doInSession(Unknown Source)
    at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:319)
    at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:40)
    at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession(GormStaticApi.groovy:835)
    at grails.gorm.DetachedCriteria.withPopulatedQuery(DetachedCriteria.groovy:737)
    at grails.gorm.DetachedCriteria.get(DetachedCriteria.groovy:114)
    at grails.gorm.DetachedCriteria.get(DetachedCriteria.groovy:113)
    at org.grails.datastore.gorm.validation.constraints.builtin.UniqueConstraint.processValidate(UniqueConstraint.groovy:75)
    at org.grails.datastore.gorm.validation.constraints.AbstractConstraint.validate(AbstractConstraint.java:88)
    at grails.gorm.validation.DefaultConstrainedProperty.validate(DefaultConstrainedProperty.groovy:601)
    at grails.gorm.validation.PersistentEntityValidator.validatePropertyWithConstraint(PersistentEntityValidator.groovy:296)
    at grails.gorm.validation.PersistentEntityValidator.validate(PersistentEntityValidator.groovy:73)
    at org.grails.orm.hibernate.AbstractHibernateGormInstanceApi.save(AbstractHibernateGormInstanceApi.groovy:123)
    at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:151)
    at org.grails.datastore.gorm.GormEntity$Trait$Helper$save.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at com.xyz.Application.save(Application.groovy)
    at com.xyz.Application.save(Application.groovy)
    at org.grails.datastore.gorm.GormEntity$save.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at com.xyz.ApplicationDetailsServiceSpec.setup(ApplicationDetailsServiceSpec.groovy:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:188)
    at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:84)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
    at org.spockframework.runtime.BaseSpecRunner.doRunSetup(BaseSpecRunner.java:400)
    at org.spockframework.runtime.BaseSpecRunner$8.invoke(BaseSpecRunner.java:382)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
    at org.spockframework.runtime.BaseSpecRunner.runSetup(BaseSpecRunner.java:375)
    at org.spockframework.runtime.BaseSpecRunner.runSetup(BaseSpecRunner.java:370)
    at org.spockframework.runtime.BaseSpecRunner.doRunIteration(BaseSpecRunner.java:323)
    at org.spockframework.runtime.BaseSpecRunner$6.invoke(BaseSpecRunner.java:309)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
    at org.spockframework.runtime.BaseSpecRunner.runIteration(BaseSpecRunner.java:288)
    at org.spockframework.runtime.BaseSpecRunner.initializeAndRunIteration(BaseSpecRunner.java:278)
    at org.spockframework.runtime.BaseSpecRunner.runSimpleFeature(BaseSpecRunner.java:269)
    at org.spockframework.runtime.BaseSpecRunner.doRunFeature(BaseSpecRunner.java:263)
    at org.spockframework.runtime.BaseSpecRunner$5.invoke(BaseSpecRunner.java:246)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
    at org.spockframework.runtime.BaseSpecRunner.runFeature(BaseSpecRunner.java:238)
    at org.spockframework.runtime.BaseSpecRunner.runFeatures(BaseSpecRunner.java:188)
    at org.spockframework.runtime.BaseSpecRunner.doRunSpec(BaseSpecRunner.java:98)
    at org.spockframework.runtime.BaseSpecRunner$1.invoke(BaseSpecRunner.java:84)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
    at org.spockframework.runtime.BaseSpecRunner.runSpec(BaseSpecRunner.java:76)
    at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:67)
    at org.spockframework.runtime.Sputnik.run(Sputnik.java:63)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

2017-08-08 18:23:22.514 DEBUG --- [           main] o.hibernate.internal.SessionFactoryImpl  : HHH000031: Closing
2017-08-08 18:23:22.514 TRACE --- [           main] o.h.engine.query.spi.QueryPlanCache      : Cleaning QueryPlan Cache
2017-08-08 18:23:22.514  INFO --- [           main] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed drop of schema as part of SessionFactory shut-down'
2017-08-08 18:23:22.515 DEBUG --- [           main] org.hibernate.SQL                        : drop table app_role if exists
2017-08-08 18:23:22.519 DEBUG --- [           main] org.hibernate.SQL                        : drop table application if exists
2017-08-08 18:23:22.519 DEBUG --- [           main] org.hibernate.SQL                        : drop table sec_role if exists
2017-08-08 18:23:22.519 DEBUG --- [           main] org.hibernate.SQL                        : drop table sec_user if exists
2017-08-08 18:23:22.519 DEBUG --- [           main] org.hibernate.SQL                        : drop table sec_user_sec_role if exists
2017-08-08 18:23:22.519 DEBUG --- [           main] o.h.b.r.i.BootstrapServiceRegistryImpl   : Implicitly destroying Boot-strap registry on de-registration of all child ServiceRegistries
2017-08-08 18:23:22.520 DEBUG --- [           main] o.h.s.i.AbstractServiceRegistryImpl      : Implicitly destroying ServiceRegistry on de-registration of all child ServiceRegistries
2017-08-08 18:23:22.520 TRACE --- [           main] o.hibernate.internal.SessionFactoryImpl  : Already closed

Stuff I tried

  • I tried setting the table name to APPLICATION in the domain class mapping configuration
  • I tried adding DATABASE_TO_UPPER=false to the connection string
  • I tried adding a delay directive to closing the connection (this should not be necessary because we use DB_CLOSE_ON_EXIT=false, but hey, shamanism, right?

I am out of ideas, now.

Updates

runtime.groovy-> application.groovy

I initially mistakenly indicated that my datasource configuration was in my runtime.groovy file. @James Kleeh kindly pointed out that this could not work in a unit test. Unfortunately, my datasource info is in application.groovy. I corrected the relevant section.

Community
  • 1
  • 1
Luis Muñiz
  • 4,649
  • 1
  • 27
  • 43

3 Answers3

5

Turns out that while upgrading my app from 3.2.x to 3.3.0, i forgot to add the following new dependency to my build:

runtime "org.apache.tomcat:tomcat-jdbc"

If I remove this dependency, the table cannot be found during unit tests. Interesting that the absence of the connection pool would make the unit tests fail in such a peculiar way.

Luis Muñiz
  • 4,649
  • 1
  • 27
  • 43
  • This fixed the issue fir me too, but we dont see the tomcat-jdbc explicitely declared in stock grails plugins. confused why is it needed. and why it works at other places. – Sudhir N Apr 19 '19 at 15:22
  • Thank you! I would have been working on this for days and never figured it out. In my case I only needed it for unit testing, so I used ```testRuntime``` scope instead of ```runtime``` – RMorrisey Mar 04 '22 at 19:49
4

Not sure if it helps, but after upgrading to Grails 3.3.0 I found DB_CLOSE_ON_EXIT=FALSE was no longer working in my project. I'm using Liquibase, and the H2 DB was getting cleared after Liquibase dropped the connection, before my app connected. Out of desperation I added DB_CLOSE_DELAY=-1, and it fixed it. No idea what's going on there.

1

Your datasource configuration is not being loaded because runtime.groovy is not part of the scripts loaded by HibernateSpec

https://github.com/grails/gorm-hibernate5/blob/master/grails-plugin/src/main/groovy/grails/test/hibernate/HibernateSpec.groovy#L45

James Kleeh
  • 12,094
  • 5
  • 34
  • 61
  • Yes, you are right, of course. I mistakenly wrote that the datasource configuration was in runtime.groovy. Actually, it is in application.groovy. Sorry about that, 'Ill correct my question – Luis Muñiz Aug 08 '17 at 18:34