';静态瞬态';和';非现场瞬态类型';GORM的声明? 让我们考虑两个GRAILS域示例类。
头等舱:';静态瞬态';和';非现场瞬态类型';GORM的声明? 让我们考虑两个GRAILS域示例类。,grails,persistence,gorm,transient,Grails,Persistence,Gorm,Transient,头等舱: class Person { String name Integer counter = 0 static transients = ['counter'] } class Vehicle { String name transient Integer counter = 0 } 二等舱: class Person { String name Integer counter = 0 static transi
class Person {
String name
Integer counter = 0
static transients = ['counter']
}
class Vehicle {
String name
transient Integer counter = 0
}
二等舱:
class Person {
String name
Integer counter = 0
static transients = ['counter']
}
class Vehicle {
String name
transient Integer counter = 0
}
类Person和类Vehicle之间整数计数器字段的GORM持久性或域类行为是否有任何差异
编辑:我知道Person类是完成Grails文档引用的任务的好方法。然而,我更喜欢车辆等级的方式,因为在阅读代码时,它似乎更明显,更容易不被忽视。这两种机制定义了不同类型的“瞬态”
static transients
定义了不应该通过Hibernate映射到数据库的bean属性,而transient
关键字表示不应该通过Java对象序列化机制保存的字段(例如,在使用webflow时)。它们在不同的情况下都有各自的用途。是的,这是事实。我知道这一点,但当一个属性被放入静态瞬态列表中时,它也不会被序列化(例如,当使用“as-XML”强制转换时)。所以它的行为类似于transient关键字。我现在还检查了,瞬态整数计数器无论如何都会导出到DB模式,所以这两个计数器之间确实没有任何共同之处。无论如何,你的回答很公平,谢谢!