表未映射到ejb3.0

时间:2013-11-08 11:22:57

标签: java mysql ejb-3.0 java-ee-6

您好我使用EJB 3而我正试图从数据库中获取一个简单的列表,但我发现此消息“travauxdereseauurbain未映射[从Travauxdereseauurbain Tr中选择Tr]”并且我真的没有得到它意味着什么< / p>

这是实体

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未映射[从中选择Tr   travauxdereseauurbain Tr]

1 个答案:

答案 0 :(得分:0)

使用createQuery而不是createNamedQuery ..

这两者之间存在差异..

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