从eclipse运行hibernate测试是可以的,但是没有gradle

时间:2014-08-23 17:29:59

标签: hibernate testing gradle

我有一些从eclipse运行得很好的hibernate测试但是,当我用gradle运行它们时,我会看到以下的stacktrace摘录:

org.hibernate.hql.internal.ast.QuerySyntaxException: Address is not mapped [delete from Address]
                at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:96)
                at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120)

地址是我的实体类之一,我无法通过JPA扫描

我的项目结构如下:

enter image description here

我是否还需要做其他事情,以便在使用gradle运行时我的休眠测试也能正常工作?

谢谢,

更新:添加了gradle构建文件

apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'

repositories { mavenCentral() }

dependencies {
    compile 'org.hibernate:hibernate-core:4.3.6.Final'
    compile 'org.hibernate:hibernate-entitymanager:4.3.6.Final'
    compile 'org.hibernate:hibernate-c3p0:4.3.6.Final'
    compile 'mysql:mysql-connector-java:5.1.32'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

task hibernateInstrumentation << {
    ant.taskdef(name: 'hibernateInstrumentation' ,
    classpath: project.sourceSets.main.compileClasspath.asPath,
    classname: 'org.hibernate.tool.instrument.javassist.InstrumentTask'){
    }
    ant.hibernateInstrumentation(verbose: 'true') {
        fileset(
                dir: "${project.buildDir}",
                include: '**/*.class'
                )
    }
    println("hibernate instrumentation")
}

compileJava.doLast { hibernateInstrumentation }

更新2:正确的gradle文件

apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'

repositories { mavenCentral() }

dependencies {
    compile 'org.hibernate:hibernate-core:4.3.6.Final'
    compile 'org.hibernate:hibernate-entitymanager:4.3.6.Final'
    compile 'org.hibernate:hibernate-c3p0:4.3.6.Final'
    compile 'mysql:mysql-connector-java:5.1.32'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

compileJava.doLast {
    ant.taskdef(name: 'hibInstrument',
    classname: 'org.hibernate.tool.instrument.javassist.InstrumentTask',
    classpath: project.sourceSets.main.compileClasspath.asPath)
    ant.hibInstrument(verbose: 'true'){
        fileset(dir:"${buildDir}/classes"){ include(name: "**/*.class") }
    }
    println("hibernate instrumentation")
}

sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir
//sourceSets.test.output.resourcesDir = sourceSets.main.output.classesDir

jar.duplicatesStrategy = DuplicatesStrategy.EXCLUDE

0 个答案:

没有答案