0

I am having a problem with my Primefaces Project. I am using Primefaces 5.2 and also Hibernate 5.0 for ORM. I am working on Eclipse and using Microsoft SQL Server. I am NOT using Maven (which I noticed several people do use). I also checked several SO questions with no positive result, including these:

unable to create managed bean primefaces

Unable to create managed bean UserBean - JSF

Previous to the error I was able to Write to my Database from a Java Controller without trouble and verified the correct insertion directly on my database.

I am now working on a LogIn validator, for which I have this class I am working on:

package modelo;

import java.util.List; 
import java.util.Date;
import java.util.Iterator; 

import org.hibernate.HibernateException; 
import org.hibernate.Session; 
import org.hibernate.Transaction;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import modelo.Empleado;

public class LoginController {

    private static SessionFactory factory;
    private String usuario;
    private String contraseña;

    public String validar(){
        try{
             factory = new Configuration().configure().buildSessionFactory();
             System.out.println("Validando");
        }
        catch (Throwable ex) { 
             System.err.println("Failed to create sessionFactory object." + ex);
             System.out.println("NOPE");
             throw new ExceptionInInitializerError(ex); 
        }

        LoginController LC = new LoginController();

        /*Verificar exista un usuario con ese login_name y contraseña*/

        Session session = factory.openSession();
        Transaction tx = null;      
        try{

            tx = session.beginTransaction();
            List validados = session.createQuery("FROM EMPLEADO WHERE contraseña ='"+contraseña+"' and nombre ='"+usuario+"'").list();

            Empleado emp = (Empleado) validados.get(0);
            if(emp == null){
                System.out.println("Error de Autenticación");
                return "login";
            }
            else{
                System.out.println("Autenticacion Correcta, User: "+usuario+", pass: "+contraseña);
                return "asistencia";
            } 
        }catch(HibernateException e){
            if (tx!=null) tx.rollback();
            e.printStackTrace(); 
        }finally{
            session.close();
        }
        return "login";
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public String getContraseña() {
        return contraseña;
    }

    public void setContraseña(String contraseña) {
        this.contraseña = contraseña;
    }

}

However, when I run it I get the following error: enter image description here

I have searched for a way to "configure" that "dependency" but with no success. I am possitive that my hibernate.cfg.xml is correctly written because I could write to my DB as mentioned above, however here is the code for that file:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>
    <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=Medidas</property>
    <property name="connection.username">sa</property>
    <property name="connection.password">***</property>
    <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

    <property name="hibernate.connection.pool_size">100</property>        
    <property name="show_sql">false</property>

    <property name="current_session_context_class">thread</property>

    <!-- Mapping files -->
    <mapping resource="Empleado.hbm.xml"/>

  </session-factory>
</hibernate-configuration>

I suspect it has something to do with the web.xml file but I did not find how to configure it. Here is my web.xml practically unchanged since I downloaded the Base Project:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         version="3.0">
  <!-- The bare minimum needed for JSF 2.2 is a servlet 2.5 or later
       declaration (this uses 3.0) and the mapping for the FacesServlet.
       Setting PROJECT_STAGE to Development is highly recommended
       during initial development so that you get more helpful
       error messages. Whether you want server-side state saving
       (default) or client-side is a more complicated question:
       client-side uses more bandwidth but fewer server resources.
       Client-side also helps to avoid the dreaded view expired exceptions.

       From JSF 2 and PrimeFaces tutorial 
       at http://www.coreservlets.com/JSF-Tutorial/jsf2/
  -->
  <!-- Hibernate Here ??? -->
  <resource-env-ref>
    <resource-env-ref-name>jdbc/DSWebAppDB</resource-env-ref-name>
    <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
  </resource-env-ref>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (default). See JSF Specification section 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <!-- If you go to http://host/project/ (with no file name), it will
       try index.jsf first, welcome.jsf next, and so forth.
   -->
  <welcome-file-list>
    <welcome-file>index.jsf</welcome-file>
    <welcome-file>welcome.jsf</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Any Ideas on what is causing my problem? Should I add configurations or dependencies that I am missing? Thanks in advance (if you need more snippets or information please do tell me)

Community
  • 1
  • 1
DarkCygnus
  • 7,420
  • 4
  • 36
  • 59
  • 1
    How did you install Hibernate? Exception basically tells that its JAR file(s) are missing in `/WEB-INF/lib` of the deployed WAR file. – BalusC Oct 02 '15 at 18:05
  • Ok, I downloaded Hibernate 5.0 and unzipped it. Then, inside its contents there is a directory called `lib/required`. There you can find all required .jar's that you need to add to your Project (Eclipse right?). This can be odne by adding external jars (maybe you have done that before). If you have not done that before just go to Run-->Run Configurations... and then in the Classpath tab add them with "Add External Jars". – DarkCygnus Oct 02 '15 at 18:11
  • I also had a problem after that, so you should include the .jar at `lib/jpa` also to the classpath (something like hibernate-entitymanager-x.x.x) – DarkCygnus Oct 02 '15 at 18:12
  • Nope. In a Maven-less project, you just drop those JARs right away in project's `/WEB-INF/lib` folder. – BalusC Oct 02 '15 at 18:12
  • Ok, do that and let me know what happens... – DarkCygnus Oct 02 '15 at 18:14
  • I managed to solve it! It was the jars that I was not including on my buildpath. Your suggestion of the other Question is Correct, my problem was similar as that – DarkCygnus Oct 02 '15 at 18:18

0 Answers0