18:29:17,782 INFO [org.hibernate.jpa.internal.util.LogHelper] (default task-2) HHH000204: Processing PersistenceUnitInfo [name: itcmedbr_PU]
18:29:18,901 INFO [org.hibernate.orm.beans] (default task-2) HHH10005002: No explicit CDI BeanManager reference was passed to Hibernate, but CDI is available on the Hibernate ClassLoader.
18:29:23,090 INFO [SQL dialect] (default task-2) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
18:29:24,051 INFO [org.hibernate.envers.boot.internal.EnversServiceImpl] (default task-2) Envers integration enabled? : true
18:29:25,945 ERROR [stderr] (default task-2) java.lang.IllegalArgumentException: org.hibernate.query.sqm.UnknownEntityException: Could not resolve root entity 'Usuarios'
I am really needing assistance.
Thanks and best regards.
There is so much wrong with this code that you posted. Why is your entity extending HttpServlet? Why do you name it so weirdly Usuarios_DAO_W1? If that really is the name of the entity that you want, why don’t you use that in your query then?
Do you realize that getResultList() will return a list of objects? You can’t just cast a list to Usuarios_DAO_W1. Use getSingleResult() if you want to load a single object.
Sorry, but it seems to me that you do not understand what you are doing and are just posting random log lines which are totally unhelpful.
I can not help you learn programming. Come back when you have an understanding of programming and have a real Hibernate ORM question.
Of course that I’m not a hibernate specialist but before to change my application to hibernate I’ve read some articles and books that I download from web then I am learning day by day but I still needing some support to solve my problems, then I opened this contact here in the forum. When I initiated this application the originally was Tomcat, Javax servlet as base but I had to change to WildFly and Jakarta. These changes was indicated by another query made on web forums.
public Usuarios_DAO_W1 getLoginW0(String Apelido, String Senha, String CNPJ) throws Exception
{
Usuarios_DAO_W1 usuario = new Usuarios_DAO_W1();
EntityManagerFactory emf = null;
EntityManager em = null;
Query query = null;
try {
emf = Persistence.createEntityManagerFactory("itcmedbr_PU");
em = emf.createEntityManager();
EntityTransaction transct = em.getTransaction();
return (Usuarios_DAO_W1) em.createQuery(
"FROM Usuarios i where i.Apelido = :apelido AND i.Senha = :senha AND i.CNPJ = :cnpj")
.setParameter("apelido", Apelido)
.setParameter("senha", Senha)
.setParameter("cnpj", CNPJ);
} catch (Exception e) {
e.printStackTrace();
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<br>");
out.println("<h1>PacientesDAO - Usuário ou senha invalido!</h1>");
out.println("</body>");
out.println("</html>");
out.close();
} finally {
if ( em != null ) {
em.close();
}
if ( emf != null ) {
emf.close();
}
}
return usuario;
}
After made some changes I am receiving another error “java.lang.IllegalArgumentException: Not an entity: itc.systems.beans.Usuarios_DAO_W1”. I included this class in my “hibernate.cfg.xml” and “hibernate-annotation.cfg.xml” and I alter my class to:
@Entity(name = "Usuarios_DAO_W1")
@Table(name = "tabela_profissional_medico")
@Access(value = AccessType.FIELD)
public class Usuarios_DAO_W1 implements Serializable {
.....
Start by doing Hibernate ORM tutorials that are known to work and progress from there.
The error simply says that the SessionFactory which you are using does not know an entity with the name itc.systems.beans.Usuarios_DAO_W1. Maybe you’re using the wrong SessionFactory or you are not properly using hibernate.cfg.xml. There are many potential problems and to rule them all out, you should rather use an example project that is pre-configured. Once you have something that you like, you can port over the code to your project, piece by piece and compare with the configuration of the working project if something doesn’t work.