在创建新的hibernatedatastore时,将应用程序中的测试更新为域中的字符串默认值会导致问题。当试图访问域时,我得到了一个错误
原因:org.h2.jdbc.jdbcsqlexception:未找到表“person”;
由于某些原因,表根本没有被构建,但是删除字符串默认值它就可以工作了。
域
@ToString(includeNames=true, includePackage=false)
class Person{
EnumType type = EnumType.Human
Long age = 10
String name = "StandardName"
static mapping = {
version false
type defaultValue: EnumType.Human
age defaultValue: 10
name defaultValue: "StandardName"
}
}
单元测试
class PersonServiceSpec extends Specification implements DataTest, BuildDataTest {
@Shared
InterviewModelService interviewModelService
@Shared
HibernateDatastore hibernateDatastore
@Shared
PlatformTransactionManager transactionManager
def setupSpec() {
mockDomain Person
hibernateDatastore = new HibernateDatastore(Person)
transactionManager = hibernateDatastore.getTransactionManager()
interviewModelService = hibernateDatastore.getService(PersonService)
}
def setup() {
}
def cleanup() {
}
@Transactional
void "test criteria builder for getting interview models"() {
setup:
Person.build(name: 'steve')
when:
def x = Person.findAll()
then:
x.size() == 3
}
}
暂无答案!
目前还没有任何答案,快来回答吧!