在域对象上设置元类属性
有什么理由不对域对象使用元类?如
domainObjectInstance.metaClass.dynamicTransientGreeting = "Hello"
这会扰乱休眠吗?
Any reason not to use metaClass on domain objects? as in
domainObjectInstance.metaClass.dynamicTransientGreeting = "Hello"
Will this mess with hibernate at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它根本不会干扰 Hibernate,因为 Hibernate 不会看到它。 GORM 仅将“真实”属性映射到 Hibernate 属性。
这就是为什么
id
和version
列以及从hasMany
声明生成的集合(例如生成的users
集合)通过static hasMany = [users: User]
使用 AST 添加到实际字节码中,如果它们仅添加到 MetaClass 中,则它们不会被看到,也不会持久。It won't mess with Hibernate at all since it won't be seen by Hibernate. GORM only maps "real" properties to Hibernate properties.
That's why the
id
andversion
columns and the collections that are generated fromhasMany
declarations (e.g. theusers
collection generated bystatic hasMany = [users: User]
are added to the actual bytecode using an AST. If they were added just to the MetaClass they wouldn't be seen and wouldn't be persistent.