2012-09-22 77 views
0

我有以下测试为什么这些Gradle测试会抛出异常?

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命令

回答

0

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

相关问题