gpt4 book ai didi

java - ejb3.0表未映射

转载 作者:行者123 更新时间:2023-11-30 01:03:49 24 4
gpt4 key购买 nike

您好,我使用 EJB 3,我正在尝试从数据库获取一个简单的列表,但我发现此消息“travauxdereseauurbain 未映射 [从 travauxdereseauurbain Tr 选择 Tr]”,我真的不明白这意味着什么

这是实体

package com.pfe.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.soap.Text;



@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;
public int getIdtru() {
return idtru;
}
public void setIdtru(int idtru) {
this.idtru = idtru;
}
public String getArticle() {
return article;
}
public void setArticle(String article) {
this.article = article;
}
public String getDesignationtraveau() {
return designationtraveau;
}
public void setDesignationtraveau(String designationtraveau) {
this.designationtraveau = designationtraveau;
}
public String getUnite() {
return unite;
}
public void setUnite(String unite) {
this.unite = unite;
}
public float getPrixHTVA() {
return prixHTVA;
}
public void setPrixHTVA(float prixHTVA) {
this.prixHTVA = prixHTVA;
}
public float getPrixTTC() {
return prixTTC;
}
public void setPrixTTC(float prixTTC) {
this.prixTTC = prixTTC;
}
public float getQtt() {
return qtt;
}
public void setQtt(float qtt) {
this.qtt = qtt;
}
public float getMontantHTVA() {
return montantHTVA;
}
public void setMontantHTVA(float montantHTVA) {
this.montantHTVA = montantHTVA;
}
public float getMontantTTC() {
return montantTTC;
}
public void setMontantTTC(float montantTTC) {
this.montantTTC = montantTTC;
}
public Traveauxdereseauurbain(int idtru, String article,
String designationtraveau, String unite, float prixHTVA, float prixTTC,
float qtt, float montantHTVA, float montantTTC) {
super();
this.idtru = idtru;
this.article = article;
this.designationtraveau = designationtraveau;
this.unite = unite;
this.prixHTVA = prixHTVA;
this.prixTTC = prixTTC;
this.qtt = qtt;
this.montantHTVA = montantHTVA;
this.montantTTC = montantTTC;
}
public Traveauxdereseauurbain() {
super();
}








}
`

和 DAO 类

     package com.pfe.data;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.pfe.controller.travauxdereseauurbainBean;
import com.pfe.model.Traveauxdereseauurbain;



import com.pfe.model.Traveauxdereseauurbain;







@Stateless
public class TravauxdereseauurbainDAO {




@PersistenceContext
private EntityManager em;


public void AddTravauxdereseauurbainDAO (Traveauxdereseauurbain Trurbain)
{
em.persist(Trurbain);
}




public Traveauxdereseauurbain affichernimpr()
{


Query q =em.createNamedQuery("select tr from travauxdereseauurbain tr");


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


}
}

`

我得到了这个错误:

Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: travauxdereseauurbain is not mapped [select Tr from travauxdereseauurbain Tr]

最佳答案

使用createQuery而不是createNamedQuery..

两者之间有区别..

在实体管理器引用之前,必须在实体上定义命名查询。这可能会更详细地解释它:http://www.objectdb.com/java/jpa/query/named

关于java - ejb3.0表未映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19857899/

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