如何为以下内容定义 EclipseLink 注释?

发布于 2024-10-04 17:15:43 字数 1152 浏览 3 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝咒 2024-10-11 17:15:43

要强制通过父查询获取任何关系,可以在 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/

来世叙缘 2024-10-11 17:15:43

我无法对此进行测试,但也许引入可嵌入对象可能会减少查询计数。像这样的东西:

@Entity
@Table(name = "FCS_ISSR_OBG")
public class FCS_ISSR_OBGDto implements Serializable {

  @Column(name = "PTY_NO", nullable = false)
  private Long pty_no;

  private List<REF_OBGDto> REF_OBGs = new ArrayList<REF_OBGDto>();

  @ElementCollection
  @CollectionTable(name = "FCS_ISSR_OBG", joinColumns = @JoinColumn(name = "PTY_NO"))
  @Column(name = "REF_OBG")
  public List<REF_OBGDto> getREF_OBGs() {
    return REF_OBGs;
  }
}

可嵌入的看起来像这样,

@Embeddable
@Table(name = "FCS_ISSR_OBG")
public class REF_OBGDto {

  @Column(name = "REF_OBG")
  public Long ref_obg;

}

只有当您特别要求时,您才会获得该集合。抱歉,答案很弱,但我只能在这里测试。

I've not been able to test this, but perhaps introducing an embeddable object may reduce the query count. Something like this:

@Entity
@Table(name = "FCS_ISSR_OBG")
public class FCS_ISSR_OBGDto implements Serializable {

  @Column(name = "PTY_NO", nullable = false)
  private Long pty_no;

  private List<REF_OBGDto> REF_OBGs = new ArrayList<REF_OBGDto>();

  @ElementCollection
  @CollectionTable(name = "FCS_ISSR_OBG", joinColumns = @JoinColumn(name = "PTY_NO"))
  @Column(name = "REF_OBG")
  public List<REF_OBGDto> getREF_OBGs() {
    return REF_OBGs;
  }
}

with the embeddable looking like this

@Embeddable
@Table(name = "FCS_ISSR_OBG")
public class REF_OBGDto {

  @Column(name = "REF_OBG")
  public Long ref_obg;

}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文