如何为以下内容定义 EclipseLink 注释?
我对 EclipseLink 的世界相对陌生,我一直在阅读文档,但是在尝试表示下表时遇到了真正的问题。
PTY_NO | REF_OBG
6544 45663
6544 1234
6544 97543
6544 1123
6544 77897
理想情况下,我想将上述数据表示如下。
@Entity
@Table(name="FCS_ISSR_OBG")
public class fcs_issr_obg implements Serializable {
@Id
@Column(name="PTY_NO")
private long pty_no;
@Column(name="REF_OBG")
private List<long> ref_obg;
...
一旦我有了这种形式的数据,我计划将该类序列化到 Coherence 缓存中。
然而,我使用的注释实际上并没有编译...
任何帮助将不胜感激。
.. 更新
到目前为止我能想到的最好的是
@Entity
@Table(name="FCS_ISSR_OBG")
public class fcs_issr_obg implements Serializable, PortableObject {
private static final long serialVersionUID = 1L;
@Id
@Column(name="PTY_NO")
private long pty_no;
@ElementCollection(targetClass = Long.class, fetch = EAGER)
@CollectionTable(
name = "FCS_ISSR_OBG",
joinColumns=@JoinColumn(name="PTY_NO")
)
@Column(name ="REF_OBG")
private List<Long> collection;
然而这会导致 2 个查询...这并不是我真正想要的。
干杯 富有的
I'm relativly new to the world of EclipseLink, I've been reading through the documentation, however I'm having a real problem trying to represent the following table.
PTY_NO | REF_OBG
6544 45663
6544 1234
6544 97543
6544 1123
6544 77897
Ideally I'd like to represent the above data as follows.
@Entity
@Table(name="FCS_ISSR_OBG")
public class fcs_issr_obg implements Serializable {
@Id
@Column(name="PTY_NO")
private long pty_no;
@Column(name="REF_OBG")
private List<long> ref_obg;
...
As once I have the data in this form I plan to serialize the class into a Coherence cache.
However the annotation I've used doesn't actually compile ...
Any help would be gratefully received.
.. update
The best I've managed to come up with so far is
@Entity
@Table(name="FCS_ISSR_OBG")
public class fcs_issr_obg implements Serializable, PortableObject {
private static final long serialVersionUID = 1L;
@Id
@Column(name="PTY_NO")
private long pty_no;
@ElementCollection(targetClass = Long.class, fetch = EAGER)
@CollectionTable(
name = "FCS_ISSR_OBG",
joinColumns=@JoinColumn(name="PTY_NO")
)
@Column(name ="REF_OBG")
private List<Long> collection;
However this results in 2 queries ... which is not really what I'm after.
Cheers
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要强制通过父查询获取任何关系,可以在 EclipseLink 中使用 @JoinFetch 注释。
不过,根据数据的不同,在单独的查询中读取集合可能是最佳解决方案。
您还可以在 EclipseLink 中使用 @BatchFetch 批量获取关系(仍然是 2 个查询,但不是 n+1 个查询)。我最近在博客中对批量和加入抓取进行了比较,请参阅
http://java-persistence- Performance.blogspot.com/
To force any relationship to be fetched with the parent query the @JoinFetch annotation can be used in EclipseLink.
Although, reading the collection in a separate query may be the best solution depending on the data.
You can also use @BatchFetch in EclipseLink to batch fetch a relationship (still 2 queries, but not n+1 queries). I did a comparison on batch and join fetching in my blog recently, see,
http://java-persistence-performance.blogspot.com/
我无法对此进行测试,但也许引入可嵌入对象可能会减少查询计数。像这样的东西:
可嵌入的看起来像这样,
只有当您特别要求时,您才会获得该集合。抱歉,答案很弱,但我只能在这里测试。
I've not been able to test this, but perhaps introducing an embeddable object may reduce the query count. Something like this:
with the embeddable looking like this
You only get the collection when you specifically ask for it. Sorry for the weak answer but I'm limited to what I can test here.