• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

fetch join

 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have 2 entitiy classes, A and B.

@Entity
class A {

@Id
Long id;
...
@ManyToMany
private Collection bs;
...

}

@Entity
class B {

@Id
Long id;
...
@ManyToMany(mappedBy="bs")
private Collection as;
...

}

An app.server builds 3 database tables :
A
B
A_B(A_ID, B_ID)


I need get all data of B which are joined with one certain object A(or ID of object).
I have tried more version of
NamedQuery but unsuccessfully. I donĀ“t what have to be a right query.

Could you help me with this.
Thank you







 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you what all Bs that have a certain A?

Try,
"Select b from B b join b.as A a where a.id = :id"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic