0

我有以下测试

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_))

摇篮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 依赖项是通过gradle idea命令安装的

4

1 回答 1

0

只有你能发现。也许类路径不同(请记住,IDEA 没有像 Gradle 那样严格的类路径分离),或者资源不同(与 Gradle 相比,这在 IDEA 中的工作方式也不同)。首先要做的是分析堆栈跟踪。在 Gradle ( -Dtest.debug=true) 中调试测试也有帮助。

于 2012-09-22T14:48:42.730 回答