How I can make a simple join query in eclipselink? I whant to receive ArrayList;
For example, I have two entity:
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;
}
And I want to execute query like this:
Select * From A a Join B b ON a.id = b.a_id Where a.value = '1';
I do that:
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();
And I receive A object which have a link to B object (bCollection) which has a link on A object (aid) and so indefinitely. Is it normal?
Yes. In
bidirectional mappingi.e. parent refers child and child refers parent, its normal. But if you don’t access the circular graph indefinitely, you are good.