简体   繁体   English

JPQL查询错误-休眠多对多关系

[英]JPQL Query Error - hibernate many to many relationship

I want to printout all 'Cuentas?' 我要打印所有的“ Cuentas”吗? that has a client name 'Paco': I have this entity: 客户名称为“ Paco”的客户:我有这个实体:

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' 解决并升级:选择所有Saldo大于10且“ CLIENTE.name” ='Paco'的“ CUENTA”

String q = "select c FROM CUENTA c, IN (c.clientesC) clientesC "
                    +"WHERE clientesC.Nombre_C = 'Paco' AND c.Saldo > 10";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM