I have 2 entities: A and B.
@Entity
@Table(name = "A")
class A{
@Id
private long id;
@OneToMany(mapped by="a")
private Set<B> b;
}
@Entity
@Table(name = "B")
class B{
@Id
private long id;
@ManyToOne
@JoinColumn(name="a")
private A a;
}
When i'm trying to make something like
Query q=sessionFactory.openSession().createQuery("select a.id, bArray
from A as a join a.b as bArray");
i'm getting not collection of B, but one B-object. How can i get A-class and collection of related with it B-objects? I.e. in debugger there is not Set with 1 element, there is just B-element.
select distinct a from A a left join fetch a.bwill return the As, each with its loaded set of Bs. There's no way to do what you want.