我有一个大问题
我的unitils.properties:
database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost/timesheet_test
database.userName=root
database.password=
database.schemaNames=timesheet_test
database.dialect=mysql
updateDataBaseSchema.enabled=true
dbMaintainer.script.locations=src/test/resources/dbscripts
dataSetStructureGenerator.xsd.dirName=target/xsd
dbMaintainer.autoCreateExecutedScriptsTable=true
dbMaintainer.disableConstraints.enabled=false
## Módulos do unitils
unitils.module.database.enabled=true
unitils.module.dbunit.enabled=true
unitils.module.hibernate.enabled=true
unitils.module.spring.enabled=true
unitils.module.mock.enabled=false
unitils.module.easymock.enabled=false
unitils.module.inject.enabled=false
unitils.module.jpa.enabled=false
DatabaseModule.Transactional.value.default=rollback
我的数据库.sql:
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
CREATE SCHEMA IF NOT EXISTS `timesheet_test` DEFAULT CHARACTER SET latin1 ;
USE `timesheet_test` ;
-- -----------------------------------------------------
-- Table `timesheet_test`.`DATA`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `timesheet_test`.`DATA` (
`ID_DATA` BIGINT(20) NOT NULL AUTO_INCREMENT ,
`DATA` DATETIME NOT NULL ,
PRIMARY KEY (`ID_DATA`) ,
UNIQUE INDEX `data_UNIQUE` (`DATA` ASC) ,
UNIQUE INDEX `ID_DIAS_UNIQUE` (`ID_DATA` ASC) )
ENGINE = InnoDB
AUTO_INCREMENT = 1000
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `timesheet_test`.`USUARIO`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `timesheet_test`.`USUARIO` (
`ID_USUARIO` BIGINT(20) NOT NULL AUTO_INCREMENT ,
`E_MAIL` VARCHAR(100) NOT NULL ,
`SENHA` VARCHAR(10) NOT NULL ,
`NOME` VARCHAR(100) NULL DEFAULT NULL ,
PRIMARY KEY (`ID_USUARIO`) ,
UNIQUE INDEX `E_MAIL_UNIQUE` (`E_MAIL` ASC) ,
UNIQUE INDEX `ID_USUARIO_UNIQUE` (`ID_USUARIO` ASC) )
ENGINE = InnoDB
AUTO_INCREMENT = 1000
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `timesheet_test`.`TIME_SHEET`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `timesheet_test`.`TIME_SHEET` (
`ID_TIME_SHEET` BIGINT(20) NOT NULL AUTO_INCREMENT ,
`INICIO` VARCHAR(8) NOT NULL ,
`FIM` VARCHAR(8) NOT NULL ,
`LONGITUDE` DOUBLE NULL DEFAULT NULL ,
`LATITUDE` DOUBLE NULL DEFAULT NULL ,
`OBSERVACAO` VARCHAR(200) NULL DEFAULT NULL ,
`ID_DATA` BIGINT(20) NOT NULL ,
`ID_USUARIO` BIGINT(20) NOT NULL ,
PRIMARY KEY (`ID_TIME_SHEET`) ,
UNIQUE INDEX `ID_TIME_SHEET_UNIQUE` (`ID_TIME_SHEET` ASC) ,
INDEX `FK9735054D39B29F66` (`ID_DATA` ASC) ,
INDEX `FK9735054D9DA5550A` (`ID_USUARIO` ASC) ,
CONSTRAINT `FK9735054D9DA5550A`
FOREIGN KEY (`ID_USUARIO` )
REFERENCES `timesheet_test`.`USUARIO` (`ID_USUARIO` ),
CONSTRAINT `FK9735054D39B29F66`
FOREIGN KEY (`ID_DATA` )
REFERENCES `timesheet_test`.`DATA` (`ID_DATA` ))
ENGINE = InnoDB
AUTO_INCREMENT = 1000
DEFAULT CHARACTER SET = latin1;
USE `timesheet_test` ;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
我有 65 个测试,但有 6 个问题和相同的错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`timesheet_test`.`time_sheet`, CONSTRAINT `FK9735054D39B29F66` FOREIGN KEY (`ID_DATA`) REFERENCES `DATA` (`ID_DATA`))
我的测试是“搜索”而不是“删除”,但我认为当 unitils 尝试删除行以开始新测试时,有问题。
有人知道吗?
谢谢