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 に答える