I have this Entity
class:
@Entity
public class Registered implements Serializable {
@Id
public RegisteredId id;
}
With this EmbeddedId
:
@Embeddable
public class RegisteredId implements Serializable {
@ManyToOne
public User user;
@ManyToOne
public Tournament tournament;
}
I'm trying to make this Criteria query
fetching the User
and the Tournament
because I need to read some of their attributes:
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Registered> criteria = builder.createQuery(Registered.class);
Root<Registered> root = criteria.from(Registered.class);
root.fetch("id.user", JoinType.LEFT);
root.fetch("id.tournament", JoinType.LEFT);
criteria.where(builder.equal(root.get("id.tournament.id"), idTournament));
List<Registered> registereds = em.createQuery(criteria).getResultList();
But I'm getting an error:
Execution exception[[CompletionException: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [id.user] on this ManagedType
What I'm doing wrong?
How can I fetch the relations on an EmbeddedId
to access them?