Jin Kwon
Jin Kwon

Reputation: 22017

joining @ManyToOne's @OneToMany

  1. Each Account has a Origin via @ManyToOne
  2. Each Origins has Shadows via @OneToMany

With given Root<Account>, How can I join those Shadows so that I can put some conditions for them on where?

final Root<Account> account;
final Path<Origin> origin = account.get(Account_.origin);

Upvotes: 1

Views: 164

Answers (1)

perissf
perissf

Reputation: 16273

Provided that the @OneToMany property in Origin entity is called shadows, you need to use Join as follows:

Join<Origin, Shadow> shadows = origin.join(Origin_.shadows);

Then, you can write conditions on Shadows properties like in this trivial String case, since Join<Z,X> has Path<X> as SuperInterface:

String name;
Predicate condition = criteriaBuilder.equals(shadows.get(Shadow_.name, name));

Upvotes: 1

Related Questions