I put the question before but as i'm new with the site i found problems writing my question. Well. I'm working on two projects: Create an EJB project and a webapp. In both i have to store information from the webapp into a database. The first one has worked. In the seconde, i am getting this error
org.hibernate.hql.internal.ast.QuerySyntaxException: Enseignants is not mapped
Here is a part of my classes
@Stateless(name = "ENIT")
public class EnitImpl implements EnitLocal {
@PersistenceContext(unitName = "tp3")
private EntityManager em ;
public EnitImpl() {
// TODO Auto-generated constructor stub
}
public void addCours(Cours cour) {
// TODO Auto-generated method stub
em.merge(cour);
}
public List<Cours> consulterCours() {
// TODO Auto-generated method stub
Query req = em.createQuery("Select c from cours c ");
return req.getResultList();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Cours consulter(int id) {
// TODO Auto-generated method stub
Cours cours = em.find(Cours.class, id);
if (cours == null)
throw new RuntimeException("Cours inexistant");
return cours;
}
public void addProf(Enseignant E) {
// TODO Auto-generated method stub
em.merge(E);
}
public List<Enseignant> consulterProf() {
Query req = em.createQuery("Select p from enseignants p ");
return req.getResultList();
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Enseignant consulterP(int id) {
Enseignant E = em.find(Enseignant.class, id);
if (E == null)
throw new RuntimeException("Enseignant non trouvé");
return E;
}
}
And the interface:
@Local
public interface EnitLocal {
public void addProf(Enseignant E);
public List<Enseignant> consulterProf();
public Enseignant consulterP(int id);
public void addCours(Cours C);
public List<Cours> consulterCours();
public Cours consulter(int id);
}
When I debug the program, em is null. I was using em.persist()
but it didn't work. So i've used em.merge()
. The diffrence between this project and the old one is that here I've this join 'ManyToOne'. Can someone see the problem?
Aucun commentaire:
Enregistrer un commentaire