gpt4 book ai didi

java - JPQL查询错误- hibernate 多对多关系

转载 作者:行者123 更新时间:2023-12-02 01:50:41 27 4
gpt4 key购买 nike

我想打印所有“Cuentas?”其客户端名称为“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>();
}

我的查询收到此错误:

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());

显示此错误,我无法找到错误的原因:

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' ]

可能是语法错误?可能是关系方向有问题?

最佳答案

已解决并升级:选择 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";

关于java - JPQL查询错误- hibernate 多对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57427858/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com