休眠覆盖@transient [英] Hibernate override @transient

查看:94
本文介绍了休眠覆盖@transient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个映射的超类,它有一个字段,我的数据库中的一些表共享。



我希望用@Transient来注释这个字段,所以大多数实体都会忽略它,但是de- @ Transient或Un- @ Transient它在子实体上。



这可能吗?



谢谢,
Idob

解决方案

您可以使用鉴别符模式



http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/ mapping.html



您必须设置父级超类,然后对其进行子类化,如

  ClassWithSharedFields 
ClassExtensionThatUpdatesCertainFields
ClassExtensionThatReadsCertainFields

然后, ClassExtensionThatReadsCertainFields 可以将您不打算更新的字段指定为只读。

这可能有点含糊不清,因此如果您想要更具体的帮助,可以提供一些更具体的例子,说明您的域类需要与您的关系DB。


I have a mapped super class, which has a field that some of the tables in my DB share.

I wish to annotate this field with @Transient so most entities will ignore it, but de-@Transient or un-@Transient it on child entities.

Is this possible?

Thank you, Idob

解决方案

You might be able to use the discriminator pattern

http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/mapping.html

You would have to set up a parent super class and then sub-class it, something like

ClassWithSharedFields
ClassExtensionThatUpdatesCertainFields
ClassExtensionThatReadsCertainFields

Then, ClassExtensionThatReadsCertainFields could specify the field that you don't intend on updating as read only.

This might be a bit of a vague suggestion, so if you want more specific help maybe provide some more concrete examples of how your domain classes need to behave in relationship to your DB.

这篇关于休眠覆盖@transient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆