GORM Grails 2.3.5分配的id不持久,被自动生成的id覆盖
我的课程是:GORM Grails 2.3.5分配的id不持久,被自动生成的id覆盖,grails,gorm,grails-2.3,Grails,Gorm,Grails 2.3,我的课程是: class Facebook { long id String username String email String first_name String last_name Date birthday String gender String link static hasMany = [friends: FacebookFriend] static constraints = { id generat
class Facebook {
long id
String username
String email
String first_name
String last_name
Date birthday
String gender
String link
static hasMany = [friends: FacebookFriend]
static constraints = {
id generator:'assigned'
birthday blank:false, nullable:true
gender blank:false, nullable:true
}
}
根据和id生成器的文档:'assigned'
是我手动设置id所需的全部。但是,每次运行代码时,该ID都会被GORM覆盖,即使我在调用.save(flush:true,failOnError:true)
方法之前手动设置了它。当我在保存之前和之后从对象输出id时,我得到的是:
保存前的ID为:12345645
保存后的ID为:1
我对Grails还不熟悉,但从我所读到的来看,我似乎在做我应该做的事情。有人能提供一些见解吗?谢谢
我的下一步是在Grails 2.3.4上运行应用程序以防万一。生成器的
属性位于映射
块中,而不是约束
:
static constraints = {
birthday blank:false, nullable:true
gender blank:false, nullable:true
}
static mapping = {
id generator: 'assigned'
}
生成器
属性位于映射
块中,而不是约束
:
static constraints = {
birthday blank:false, nullable:true
gender blank:false, nullable:true
}
static mapping = {
id generator: 'assigned'
}