I want to printout all 'Cuentas?' that has a client name 'Paco': I have this entity:
public class Cuenta implements Serializable{
private static final long serialVersionUID = 1L;
@ManyToMany(mappedBy = "cuentasC",fetch = FetchType.LAZY)
private Set<Cliente> clientesC = new HashSet<Cliente>();
}
@Entity(name = "CLIENTE")
public class Cliente implements Serializable{
@Column(name = "Nombre", length = 30, nullable = false)
private String Nombre_C;
@ManyToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
private Set<Cuenta> cuentasC = new HashSet<Cuenta>();
}
And I have this query getting this error:
String q = "select c FROM CUENTA c, IN (cuentas.clientesC) cli "+"WHERE CLIENTE cli.Nombre = 'Paco' ";
Query query = em.createQuery(q);
List<Cuenta> resultado = query.getResultList();
System.out.println(resultado.toString());
Showing this error that i couln't find why is wrong:
unexpected token: cli near line 1, column 76 [select c FROM entidades.Cuenta c, IN (cuentas.clientesC) cli WHERE CLIENTE cli.Nombre = 'Paco' ]
unexpected token: cli near line 1, column 76 [select c FROM entidades.Cuenta c, IN (cuentas.clientesC) cli WHERE CLIENTE cli.Nombre = 'Paco' ]
It could be a syntax error? Could be a problem with the direction of the relationships?
Solved and upgraded: Select all "CUENTA" that have Saldo greater that 10 and a "CLIENTE.name" = 'Paco'
String q = "select c FROM CUENTA c, IN (c.clientesC) clientesC "
+"WHERE clientesC.Nombre_C = 'Paco' AND c.Saldo > 10";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.