Struts2:无法在DAO类中加载HibernateSessionFactory.getSession()

时间:2013-12-31 04:05:29

标签: java hibernate struts2 jboss

我在JBoss服务器上运行一个应用程序,它是使用struts2&休眠。但我在LoginDAOImpl类的getEmployee方法中遇到问题。代码如下: -

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

配置文件如下: -

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.-->
<hibernate-configuration>
<session-factory>
    <property name="connection.username">root</property>
    <property name="dialect">
        org.hibernate.dialect.MySQLDialect
    </property>
    <property name="connection.password">root</property>
    <property name="connection.url">
        jdbc:mysql://192.168.1.90:3307/esupport
    </property>
    <property name="connection.driver_class">
        com.mysql.jdbc.Driver
    </property>
    <property name="show_sql">true</property>

    <mapping class="com.Allied.dto.ActionView" />
    <mapping class="com.Allied.dto.LeaveDto" />
    <mapping class="com.Allied.dto.LeaveTypeDto" />
    <mapping class="com.Allied.dto.RoleActionMap" />
    <mapping class="com.Allied.dto.RoleView" />
    <mapping class="com.Allied.dto.TimesheetTask" />
    <mapping class="com.Allied.dto.UserRoleMap" />
    <mapping class="com.Allied.dto.UserView" />
    <mapping class="com.Allied.dto.EmployeeDetailsDto" />
    <mapping class="com.Allied.dto.EmployeeLeave" />
    <mapping class="com.Allied.dto.ItdfDetails" />
    <mapping class="com.Allied.dto.Project" />
    <mapping class="com.Allied.dto.EmployeeER" />
    <mapping class="com.Allied.dto.EmployeeTimesheet" />
    <mapping class="com.Allied.dto.ExpenseReportDto" />
    <mapping class="com.Allied.dto.TRStatusDto" />
</session-factory>

</hibernate-configuration>


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

2 个答案:

答案 0 :(得分:0)

这是在您的开发环境中运行吗?该类是否编译正确。我想知道问题是由环境,配置或代码引起的。

答案 1 :(得分:0)

您需要检查的一些可能解决问题的方法是, 1.检查环境设置,包含路径等 2.检查进口报表 3.确保HibernateSessionFactory属于所需的类,因为它可能来自其他一些导入的类或jar。
4.构建项目并检查其构建类目录中是否生成了.class文件。
5.debug HibernateSessionFactory.getSession()方法并查找错误原因 回复这个问题的状况。
希望它能解决你的问题。