gpt4 book ai didi

java - Eclipse链接简单加入

转载 作者:行者123 更新时间:2023-11-30 11:40:01 25 4
gpt4 key购买 nike

如何在 eclipselink 中进行简单的连接查询?我想接收 ArrayList;例如,我有两个实体:

public class A implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Long id;
@Column(name = "value")
private String value;

@OneToMany(mappedBy = "aid")
private Collection<B> bCollection;

public class B implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Long id;

@JoinColumn(name = "a_id", referencedColumnName = "id")
@ManyToOne
private A aid;

我想像这样执行查询:

Select * From A a Join B b ON a.id = b.a_id Where a.value = '1';

我这样做:

EntityManager em = createEntityManager();
Query q = em.createQuery("Select a From A a Where a.value = 1");
q.setHint("eclipselink.join-fetch", "a.bCollection");
Object result = q.getResultList();

我收到一个对象,它有一个链接到 B 对象 (bCollection),它有一个关于 A 对象 (aid) 的链接,等等。正常吗?

最佳答案

是的。在双向映射中,即parent引用child,child引用parent,这是正常的。但是,如果您不无限期地访问圆形图,您就很好。

关于java - Eclipse链接简单加入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12947778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com