Could not resolve root entity 'MyEntity'

I am trying to read my mysql columns but can’t do this and can’t see where I am wronging, below is my method to to do this.

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();
        	
        	query = em.createQuery(
        			"from Usuarios i where i.Apelido = ?1 and i.Senha = ?2 and i.CNPJ = ?3", Usuarios_DAO_W1.class);
        	
        	query.setParameter(1, Apelido);
        	query.setParameter(2, Senha);
        	query.setParameter(3, CNPJ);
        	
        	usuario = (Usuarios_DAO_W1) query.getResultList();
        	
        	
		} 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;
	}

My entity class:

@Entity
@Table(name = "tabela_profissional_medico")
@Access(value = AccessType.FIELD)
public class Usuarios_DAO_W1 extends HttpServlet implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
    private Integer ind;
	@Column(name = "CNPJ")
    private String cnpj;
	@Column(name = "Nome")
    private String nome;
	@Column(name = "Apelido")
    private String apelido;
	@Column(name = "Email")
    private String email;
	@Column(name = "Cremerj")
    private String cremerj;
	@Column(name = "Coren")
    private String coren;
	@Column(name = "Senha")
    private String senha;
	@Column(name = "Tipo")
    private String tipo;
	@Column(name = "Celular")
    private String celular;
// Getters, Setters and ToString

Here part of log error:

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?

   	usuario = (Usuarios_DAO_W1) query.getResultList();

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.

Hi Beikov thanks by contact, I changed my entity from servlet to class:

@Entity(name = "Usuarios")
@Table(name = "tabela_profissional_medico")
@Access(value = AccessType.FIELD)
public class Usuarios_DAO_W1 implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
    private Integer ind;
	@Column(name = "CNPJ")
    private String cnpj;
	@Column(name = "Nome")
    private String nome;
	@Column(name = "Apelido")
    private String apelido;
	@Column(name = "Email")
    private String email;
	@Column(name = "Cremerj")
    private String cremerj;
	@Column(name = "Coren")
    private String coren;
	@Column(name = "Senha")
    private String senha;
	@Column(name = "Tipo")
    private String tipo;
	@Column(name = "Celular")
    private String celular;

The error log say that the error is in this line:

 query = em.createQuery(
        			"from Usuarios i where i.Apelido = ?1 and i.Senha = ?2 and i.CNPJ = ?3");

Log error:

07:41:48,222 ERROR [stderr] (default task-1) 	at deployment.itcmedbr.war//itc.systems.beans.PacientesDAO_W01.getLoginW0(PacientesDAO_W01.java:2943)

I changed too the query from list to getSingleResult as you say, after made the changeds the problem still the same.

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;
	}

Thanks.

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 {
.....

hibernate.cfg.xml:

<hibernate-configuration>
 <session-factory>
  <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
 <property name="connection.url">jdbc:mysql://localhost:3306/DB_Medical</property>-->
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/DB_Medical</property>
  <property name="connection.username">root</property>
  <property name="connection.password">root</property>
  <property name="connection.pool_size">10</property>
  <property name="dialect">org.hibernate.dialect.MySQL8Dialect</property>
  <property name="show_sql">true</property>
  <property name="format_sql">true</property>
  <property name="current_session_context_class">thread</property>
  <property name="hbm2ddl.auto">update</property>
  <!--Mapeando classes-->
  <mapping class="itc.systems.beans.Bean_Pre_Natal"/>
  <mapping class="itc.systems.beans.Bean_Visita_Internados"/>
  <mapping class="itc.systems.beans.BeanConsumoInternados"/>
  <mapping class="itc.systems.beans.BeanDadosPessoais"/>
  <mapping class="itc.systems.beans.Usuarios_DAO_W1"/>
 </session-factory>
</hibernate-configuration>

hibernate-annotation.cfg.xml:

<hibernate-configuration>
 <session-factory name="">
  <!-- Database connection properties - Driver, URL, user, password -->
  <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/DB_Medical</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.connection.password">root</property>
  <!-- org.hibernate.HibernateException: No CurrentSessionContext configured! -->
  <property name="hibernate.current_session_context_class">thread</property>
  <property name="hbm2ddl.auto">update</property>
  <!-- Mapping with model class containing annotations -->
  <mapping class="itc.systems.beans.Bean_Pre_Natal"/>
  <mapping class="itc.systems.beans.Bean_Visita_Internados"/>
  <mapping class="itc.systems.beans.BeanConsumoInternados"/>
  <mapping class="itc.systems.beans.BeanDadosPessoais"/>
  <mapping class="itc.systems.beans.Usuarios_DAO_W1"/>
 </session-factory>
</hibernate-configuration>

I don’t have any idea to solve this.

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.