我有以下测试
answer = Author.withCriteria {
books {
gt 'price', new DetachedCriteria(Book).build {
projections {
avg 'price'
}
}
}
}
assert answer.size() == 1
Intellij IDEA无异常地执行此测试。如果我运行gradle build
,则此测试会增加org.hibernate.exception.SQLGrammarException: could not execute query
例外。
Intellij生成以下SQL:
select this_.id as id2_1_, this_.version as version2_1_, this_.age as age2_1_, this_.email as email2_1_, this_.first_name as first5_2_1_, this_.home_page as home6_2_1_, this_.last_name as last7_2_1_, this_.login as login2_1_, this_.salary as salary2_1_, this_.sex as sex2_1_, (SELECT count(*) FROM BOOK b WHERE b.author_id = this_.id) as formula0_1_, books_alia1_.id as id1_0_, books_alia1_.version as version1_0_, books_alia1_.author_id as author3_1_0_, books_alia1_.date_created as date4_1_0_, books_alia1_.last_updated as last5_1_0_, books_alia1_.price as price1_0_, books_alia1_.title as title1_0_ from author this_ inner join book books_alia1_ on this_.id=books_alia1_.author_id where (books_alia1_.price > (select avg(cast(this_.price as double)) as y0_ from book this_))
Gradle SQL:
select this_.id as id2_1_, this_.version as version2_1_, this_.age as age2_1_, this_.email as email2_1_, this_.first_name as first5_2_1_, this_.home_page as home6_2_1_, this_.last_name as last7_2_1_, this_.login as login2_1_, this_.salary as salary2_1_, this_.sex as sex2_1_, (SELECT count(*) FROM BOOK b WHERE b.author_id = this_.id) as formula0_1_, books_alia1_.id as id0_0_, books_alia1_.version as version0_0_, books_alia1_.author_id as author3_0_0_, books_alia1_.date_created as date4_0_0_, books_alia1_.last_updated as last5_0_0_, books_alia1_.price as price0_0_, books_alia1_.title as title0_0_ from author this_ inner join book books_alia1_ on this_.id=books_alia1_.author_id where (books_alia1_.price > (select from book this_)
您可以看到avg 'price'
部分的问题。
问题是一样的:为什么Gradle执行的测试有例外?
PS
Intellij dependecies由gradle idea
命令
答案 0 :(得分:0)
只有你能找到答案。也许类路径是不同的(请记住,IDEA没有像Gradle那样严格的类路径分离),或者资源是不同的(再次,与Gradle相比,这在IDEA中的工作方式不同)。首先要做的是分析堆栈跟踪。在Gradle(-Dtest.debug=true
)中调试测试也可以提供帮助。