Could not resolve root entity 'Usuarios'

738 views
Skip to first unread message

Cezar Apulchro

unread,
Nov 21, 2023, 12:42:44 PM11/21/23
to WildFly
Hi guys, 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 = null;

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(

"select i from Usuarios i where i.Apelido = ?1 and Senha = ?2 and cnpj = ?3"

);

query.setParameter(1, Apelido);

query.setParameter(2, Senha);

query.setParameter(3, CNPJ);

em.close();

} catch (Exception e) {

e.printStackTrace();

System.out.println("Caiu no catch senha invalida....");

log.info("Retorno: " + usuario);

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;

}

"

I appreciate any help.

Thanks and best regards.


Jens Kutschke

unread,
Nov 29, 2023, 3:42:38 PM11/29/23
to WildFly
You need to have an entity class with name Usuarios

Cezar Apulchro

unread,
Dec 1, 2023, 6:44:14 AM12/1/23
to WildFly
My entity:
"

@Table(name = "tabela_profissional_medico")

@Access(value = AccessType.FIELD)

@Entity(name = "Usuarios")

public class Usuarios_DAO_W1 implements Serializable {


private static final long serialVersionUID = 1L;

@Id

@GeneratedValue(strategy = GenerationType.AUTO)

@Column(name = "IND")

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

          .............
"
My method to read mysql:
"

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 by assistance.

Cezar Apulchro

unread,
Dec 3, 2023, 12:54:56 PM12/3/23
to WildFly
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.

Scott Marlow

unread,
Dec 4, 2023, 1:17:50 PM12/4/23
to Cezar Apulchro, WildFly
You might want to review the Hibernate ORM output sent to the WildFly server.log file that is also shown in the console during application deployment.  If that doesn't help, try to set TRACE log output for Hibernate ORM as mentioned in https://docs.wildfly.org/30/Developer_Guide.html#troubleshooting

"
<subsystem xmlns="urn:jboss:domain:logging:1.0">
     <console-handler name="CONSOLE">
      <level name="TRACE" />
      ...
     </console-handler>
 ... 
     <logger category="org.hibernate.SQL">
        <level name="TRACE" />
     </logger>
"

You might look for references to "Usuarios_DAO_W1" in the server.log file.

Scott

--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/2af9bd69-d931-489f-a8da-25718766a5ecn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages