0

您好,我使用 EJB 3,我正在尝试从 DB 获取一个简单列表,但我发现此消息“travauxdereseauurbain is not mapped [select Tr from travauxdereseauurbain 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);


    }
}

`

我得到了这个错误:

引起:javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: travauxdereseauurbain 未映射 [从 travauxdereseauurbain Tr 中选择 Tr]

4

1 回答 1

0

使用 createQuery 而不是 createNamedQuery..

这两者是有区别的。。

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

于 2013-11-08T11:24:59.797 回答