2

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?

Terence
  • 69
  • 1
  • 11

1 Answers1

1

Yes. In bidirectional mapping i.e. parent refers child and child refers parent, its normal. But if you don't access the circular graph indefinitely, you are good.

Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73