当我尝试在静态脚手架中创建新的Employee时,我收到以下错误:
错误500:内部服务器错误
URI / file-tracker / employee / save Class org.hibernate.StaleStateException消息 批量更新从update [0]返回意外的行数;实际行数:0;预期:1
第38行 的grails-app /控制器/组织/ simpragma / EmployeeController.groovy
围绕PageFragmentCachingFilter.java的第191行
有什么问题?
package org.xyz
class Employee {
String name;
String department;
String role;
String userId;
String pw;
static mapping = {
table 'employee'
version false
id name: 'userId'
id generator: 'native'
}
static hasMany = [toAllocations: Allocation, fromAllocations: Allocation]
static mappedBy = [toAllocations: 'toEmployee', fromAllocations: 'fromEmployee']
static constraints = {
department nullable : true
role nullable : true
}
}
package org.xyz
class Allocation {
static hasOne = [file:File, toEmployee:Employee, fromEmployee:Employee, remark:Remark]
static mappedBy = [toEmployee: 'toAllocations', fromEmployee: 'fromAllocations' ]
static constraints = {
remark nullable: true
}
}
package org.xyz
class File {
String fileNumber;
Date requestedDate;
String requestedBy;
String priority;
Double budget;
String requestedByDepartment;
String subject;
static mapping = {
id name: 'fileNumber'
version false
id generator: 'native'
}
static hasMany = [allocations: Allocation]
static constraints = {
fileNumber nullable : true
priority nullable : true
budget nullable : true
}
}
package org.xyz
class Remark {
String remark;
Date remarkDate;
static belongsTo = [allocation: Allocation];
static constraints = {
}
}
答案 0 :(得分:0)
就我而言,出于测试目的,我试图将自己的id分配给对象。如果在保存期间应该生成id,我就不能这样做。