我正在尝试使用一些简单的域类创建一个新的grails 3.3.0应用程序。
我也在使用新的HibernateSpec(随GORM 6.1.x推出)为我的单元测试创建一个内存H2数据库。
我将此技术用于以前版本的grails,但现在使用grails 3.3.0我遇到了系统故障。
Hibernate似乎创建了表,但是当我尝试在单元测试中执行查询时,它会抱怨找不到表。
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"
}
}
}
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
class Application {
String name
static constraints = {
name unique: true, nullable: false, blank: false, maxSize: 40
}
}
spring-security-core生成的典型SecUser
,SecRole
,SecUserSecRole
。
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)
}
}
我已在org.hibernate
启用了logback.groovy
跟踪,以了解hibernate在幕后的用途,我可以看到DDL正在(显然)执行:
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
我现在没有想法了。
我最初错误地指出我的数据源配置在我的runtime.groovy文件中。 @James Kleeh善意地指出,这在单元测试中无法奏效。不幸的是,我的数据源信息在application.groovy中。我更正了相关部分。
答案 0 :(得分:3)
事实证明,在将我的应用程序从3.2.x升级到3.3.0时,我忘记将以下新依赖项添加到我的构建中:
runtime "org.apache.tomcat:tomcat-jdbc"
如果删除此依赖项,则在单元测试期间无法找到该表。有意思的是,连接池的缺失会使单元测试以一种特殊的方式失败。
答案 1 :(得分:2)
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.
答案 2 :(得分:1)
您的数据源配置未加载,因为<input type="file" name="files" id="file" />
<input type="file" name="files" id="file" />
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files) {...
不是runtime.groovy