java hibernate tomcat配置-会话将不会打开

java hibernate tomcat配置-会话将不会打开,java,hibernate,jakarta-ee,tomcat,servlets,Java,Hibernate,Jakarta Ee,Tomcat,Servlets,我正在尝试配置hibernate和tomcat,以便tomcat管理数据库连接,但我遇到了一些错误。 你能帮忙吗?这是我的密码: 这是冬眠球 public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { try {

我正在尝试配置hibernate和tomcat,以便tomcat管理数据库连接,但我遇到了一些错误。 你能帮忙吗?这是我的密码: 这是冬眠球

public class HibernateUtil {  
private static final SessionFactory sessionFactory = buildSessionFactory();  

private static SessionFactory buildSessionFactory() {  
    try {  
        // Create the SessionFactory from hibernate.cfg.xml  
        return new AnnotationConfiguration().configure().buildSessionFactory();  

    } catch (Throwable ex) {  
        // Make sure you log the exception, as it might be swallowed  
        System.err.println("Initial SessionFactory creation failed." + ex);  
        throw new ExceptionInInitializerError(ex);  
    }  
}  

public static SessionFactory getSessionFactory() {  
    return sessionFactory;  
}  

public static void shutdown() {  
    // Close caches and connection pools  
    getSessionFactory().close();  
}  
}  
HibernateListener:

我还在web.xml中做了一个条目

  <listener>
<listener-class>hibernate.HibernateListener</listener-class>
</listener>
我得到的错误是:

org.apache.jasper.JasperException: org.hibernate.HibernateException: createQuery is   not valid without active transaction
我试着用类似于中描述的方法来做,但没有成功。。。。
再一次。请提供帮助。

开始处理会话。该睡觉了。。。很容易。谢谢:
public Employee getEmployeeByLogin(String login){
    Employee p= null;
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Query query = session.createQuery("from employee p where p.login = '" + login +"'");
    p = (Employee) query.uniqueResult();
    return p;
}
org.apache.jasper.JasperException: org.hibernate.HibernateException: createQuery is   not valid without active transaction