[英]With JPA 2.0, how can one specify that a property/attribute of an embedded object as not persistent?
So, I have an object that is embedded via the @Embedded
annotation in several entities. 因此,我有一个通过
@Embedded
注释嵌入到多个实体中的对象。 I would like to exclude a property/attribute from being persisted in one instance where it is embedded but not the other. 我想从一个属性/属性中将其保留在嵌入其中的一个实例中,而不将其保留在另一个实例中。 Is there a concise way to do this?
有一种简洁的方法吗? Should I do this?
我应该这样做吗? If not, why not?
如果没有,为什么不呢? I'm using spring-data-jpa 1.7.1, eclipselink 2.5.1.
我正在使用spring-data-jpa 1.7.1,eclipselink 2.5.1。 Thanks in advance!
提前致谢!
Ken 肯
Firstly you cannot use annotations if you want to persist a field of a class (whether embedded or otherwise) differently in one place than another (since an annotation is specified in one place only), or at least I can't see how it would be possible. 首先,如果您要在一个地方与另一个地方(因为仅在一个地方指定了注释)不同而持久地保留一个类的字段(无论是嵌入的还是其他形式的),则不能使用注释,或者至少我看不到它将如何可能的。
Secondly, with XML you could specify an "embedded" element and under that "attributes" and for each attribute you could put "transient". 其次,使用XML,您可以指定一个“嵌入式”元素,并在该“属性”下,并为每个属性放置“瞬态”。 Never tried it mind, but that would be the way I'd go
没尝试过,但这就是我要走的路
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.