J'ai créé une requête SQL
que je veux réécrire en JPQL
. Ci-dessous il y a une requête SQL
et mon exemple de JPQL
. Je dois vous informer que dans la requête SQL
j'utilise la table de fonction appelée wash_admin
qui n'est pas mappée dans la classe Java
. SQL
requête:Comment réécrire correctement la requête SQL à JPQL
select ww.wash_id, ww.name, ww.washlocation_wash from test3.user us
join test3.admin ad on us.user_id = ad.user_id
join test3.wash_admin wa on wa.admin_id = ad.admin_id
join test3.wash ww on ww.wash_id = wa.wash_id
where 1=1
and us.login = 'ADMIN11';
Mon JPQL
:
@Query(value = "select w from Wash w left join w.washAdmins wa left join wa.userId us where us.login = :login")
List<Wash> getWashByLogin(@Param("login") String login);
Wash
:
public class Wash {
private Integer washId;
private String name;
private WashLocation washLocation;
private List<Worker> washWorker;
private List<Reservation> washReservation;
private List<WashWashType> washTypes;
private List<Admin> washAdmins;
User
:
public class User {
private Integer userId;
private String login;
private String passwordHash;
private Role userRole; // admin, worker, client
private Client userClient;
private Worker userWorker;
private List<File> file;
private Admin userAdmin;
Admin
:
public class Admin {
private Integer adminId;
private User userId;
private List<Wash> washId;
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "wash_admin", joinColumns = {
@JoinColumn(name = "adminId") },
inverseJoinColumns = { @JoinColumn(name = "washId") })
public List<Wash> getWashId() {
return washId;
}
Malheureusement, quand j'ai couru cette query
je suis arrivé exception:
Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8.; nested exception is java.lang.IllegalArgumentException:
Mais le principal questoion à ce sujet est la façon de réécrire correctement pour obtenir le résultat même qu'il est dans SQL
requête?