gpt4 book ai didi

java - 未找到命名查询

转载 作者:行者123 更新时间:2023-12-01 13:52:33 26 4
gpt4 key购买 nike

我使用 EJB 3,我试图从数据库获取一个简单的字符串,但我收到此消息

Named query not found: SELECT tr FROM Travauxdereseauurbain tr

我不太明白这意味着什么。

这是实体

@Entity
@Table(name="Travauxdereseauurbain")
public class Traveauxdereseauurbain implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name="idtru")
private int idtru;
@Column(name ="article")
private String article;
@Column (name="designationtraveau")
private String designationtraveau;
@Column(name="unite")
private String unite;
@Column(name="prixHTVA")
private float prixHTVA;
@Column(name="prixTTC")
private float prixTTC;
@Column (name="qtt")
private float qtt;
@Column(name="montantHTVA")
private float montantHTVA;
@Column(name="montantTTC")
private float montantTTC;


///GETTERS, SETTERS AND CONSTRUCTOR
}

和 DAO 类

@Stateless
public class TravauxdereseauurbainDAO {

@PersistenceContext
private EntityManager em;

public Traveauxdereseauurbain affichernimpr()
{


Query q =em.createNamedQuery("SELECT tr FROM Travauxdereseauurbain tr");

return (Traveauxdereseauurbain) q.getResultList().get(0);
}
}

最后的错误消息是:

Servlet.service()" pour la servlet Faces Servlet a généré une exception: java.lang.IllegalArgumentException: Named query not found: SELECT tr FROM Travauxdereseauurbain tr

提前谢谢你

最佳答案

您没有调用正确的方法。您需要调用em.createQuery .

关于java - 未找到命名查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19862020/

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