0

I am running an application on JBoss server which is developed using struts2 & Hibernate. But I am facing a problem in my getEmployee method of LoginDAOImpl class.The code is as below:-

@SuppressWarnings("unchecked")
public List<UserView> getEmployee(String empId) {
    Session session = null;
    List<UserView> list = null;
    try {
        System.out.println("in LoginDAOImpl getEmployee : 1 ");
        session = HibernateSessionFactory.getSession();
        System.out.println("in LoginDAOImpl getEmployee : 2 " + session);
        String str = "from UserView  where empId='" + empId + "'";
        list = session.createQuery(str).list();
        System.out.println("LoginDAOImpl.getEmployee()::" + empId);
    } catch (HibernateException e) {
        e.printStackTrace();
    } finally {
        HibernateSessionFactory.closeSession();
    }
    return list;
}

On Console Iam getting "in LoginDAOImpl getEmployee : 1 " but i am not getting "in LoginDAOImpl getEmployee : 2 ".That means it is not able to find Hibernatesessionfactory class.But I have included Hibernatesessionfactory in my path. I have included jars for Hibernate :- hibernate3.jar,hibernate-annotations-3.2.1.ga.jar,hibernate-annotations.jar,hibernate-commons-annotations.jar,hibernate-entitymanager.jar,hibernate-valid

BenMorel
  • 34,448
  • 50
  • 182
  • 322
3076843
  • 65
  • 8

2 Answers2

0

Try

session = HibernateSessionFactory.openSession();
Prabhakar Manthena
  • 2,223
  • 3
  • 16
  • 30
  • Actually in my HibernateSessionFactory class there is no openSession method..so it is showing error after writing – 3076843 Dec 30 '13 at 11:50
0

You can give something like :

     @SuppressWarnings("unchecked")
        public List<UserView> getEmployee(String empId) {
                private static SessionFactory factory; 
                 try{
                      factory = new Configuration().configure().buildSessionFactory();
                 }catch (Throwable ex) { 
                    System.err.println("Failed to create sessionFactory object." + ex);
                     throw new ExceptionInInitializerError(ex); 
                 }

            Session session = null;
            List<UserView> list = null;
            try {
                System.out.println("in LoginDAOImpl getEmployee : 1 ");
                session = factory.openSession();
                System.out.println("in LoginDAOImpl getEmployee : 2 " + session);
                String str = "from UserView  where empId='" + empId + "'";
                list = session.createQuery(str).list();
                System.out.println("LoginDAOImpl.getEmployee()::" + empId);
            } catch (HibernateException e) {
                e.printStackTrace();
            } finally {
                session.close();
            }
            return list;
        }

Refer this link and link2 for more details .

Community
  • 1
  • 1
Sujith PS
  • 4,776
  • 3
  • 34
  • 61
  • after adding the above code i am still facing some exception but is different frm previous one:- – 3076843 Dec 30 '13 at 12:29
  • java.lang.ExceptionInInitializerError com.Allied.dao.LoginDAOImpl.getEmployee(LoginDAOImpl.java:153) com.Allied.service.LoginServiceImpl.getEmployee(LoginServiceImpl.java:29) com.Allied.action.LoginAction.loginCheck(LoginAction.java:101) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) – 3076843 Dec 30 '13 at 12:29
  • root cause java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:189) org.slf4j.LoggerFactory.bind(LoggerFactory.java:112) org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:105) org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:235) org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:208) org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:221) org.hibernate.cfg.Configuration.(Configuration.java:151) – 3076843 Dec 30 '13 at 12:30
  • Can you give the code of your configuration file (xml file ) also , with your question ? – Sujith PS Dec 30 '13 at 12:52
  • here is my config file:- root org.hibernate.dialect.MySQLDialect root – 3076843 Dec 30 '13 at 13:15
  • jdbc:mysql://192.168.1.90:3307/esupport com.mysql.jdbc.Driver true – 3076843 Dec 30 '13 at 13:15
  • It will be better , if you update your question with this configuration details NOT AS COMMENT (for better readability). – Sujith PS Dec 30 '13 at 13:46