Hibernate Grails集成测试错误具有相同标识符值的不同对象已与会话关联

Hibernate Grails集成测试错误具有相同标识符值的不同对象已与会话关联,hibernate,grails,gorm,Hibernate,Grails,Gorm,我有以下集成测试: @Integration @Rollback class IndustryDataServiceSpec extends Specification { @Shared Sector techSector Industry AI Industry HCI def industryDataService def setup() { techSector = new Sector(name: "Technol

我有以下集成测试:

@Integration
@Rollback

class IndustryDataServiceSpec extends Specification {

    @Shared
    Sector techSector
    Industry AI
    Industry HCI
    def industryDataService

    def setup() {

        techSector = new Sector(name: "Technology")
        techSector.save(flush: true)
        AI = new Industry(name: "Artificial Intelligence")
        HCI = new Industry(name: "HCI")
        techSector.addToIndustries(AI)
        techSector.addToIndustries(HCI)

    }

    def "attach the sector to the industry"() {

        when: "the industry is saved"

        def messageAI = industryDataService.insertIndustry(AI)
        def messageHCI = industryDataService.insertIndustry(HCI)

        then: "the industry should be saved and render the message"
        messageAI == AI.name + " has been saved"
        messageHCI == HCI.name + " has been saved"
    }

    def "get the industries which match the sector"() {
        given: "a sector name"
        String tech = "Technology"

        when: "get the industries"
        def industryList = industryDataService.getIndustriesToSector(tech)

        then: "only the industries which are within this sector should be returned"
        industryList.size == 2
    }

    def cleaup() {
        AI.delete(flush: true)
        HCI.delete(flush: true)
        techSector.delete(flush: true)
    }

}
industryDataService.insertIndustry
如下所示:

def insertIndustry(Industry newIndustry) {

    def message
    if (newIndustry != null) {
        if (newIndustry.validate()) {
            newIndustry.save(flush: true)
            message = newIndustry.name + " has been saved"
        } else {
            message = newIndustry.name + " is not valid"
        }
    } else {

        message = "Insert a Industry"
    }

    return message
}
运行此测试时,我遇到以下错误:

org.springframework.dao.DuplicateKeyException: A different object with the same identifier value was already associated with the session : 
集成测试在H2测试数据库上运行,并且包含了回滚注释以从数据库中删除保存的实例。我不完全确定为什么会出现这个错误,因为数据库中应该没有任何内容