在我当前的更新函数的保存部分(我尝试了flush:true和insert:true)每次我尝试都会执行一个插入。
我要更新的列是主键,但在 mysql-database 中,我在所有外键使用中都有 ON UPDATE CASCADE。
在 grails 或其他地方我还有什么需要注意的吗?
更新:我有以下表格:
CREATE TABLE IF NOT EXISTS `Station` (
`Name` CHAR(50) NOT NULL ,
`Location_Designation` CHAR(50) NOT NULL ,
PRIMARY KEY (`Name`, `Location_Designation`) ,
INDEX `fk_Station_Location1_idx` (`Location_Designation` ASC) ,
CONSTRAINT `fk_Station_Location_LocatedIn`
FOREIGN KEY (`Location_Designation` )
REFERENCES `Location` (`Designation` )
ON DELETE NO ACTION
ON UPDATE CASCADE)
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `Location` (
`Designation` CHAR(50) NOT NULL ,
PRIMARY KEY (`Designation`) )
ENGINE = InnoDB;
我的圣杯:
stationInstance.properties = params
//Station = "S1", Location="test"
if (!stationInstance.save(flush: true)) { // }
更新2:这是我的休眠在更新命令中所做的:
Hibernate: select station_.name, station_.Location_Designation as Location2_2_ from station station_ where station_.name=?
Hibernate: insert into station (Location_Designation, name) values (?, ?)