currentSession 看看你得代码里面是不是 SESSION==NULL 得时候你就开始使用了

解决方案 »

  1.   

    HibernateSessionFactory.java等都是myeclipse自动生成的!AdminDAOFactory.java
    public List getProd() throws HibernateException {
    session = HibernateSessionFactory.currentSession();
    Transaction tx = session.beginTransaction();
    Query query = session.createQuery("from Prod as prod");
    List list = query.list(); 
    tx.commit();
    HibernateSessionFactory.closeSession();
    return list; 
    }
    show.jsp
        AdminDAOFactory db=new AdminDAOFactory(); for (Iterator it = db.getProd().iterator(); it.hasNext();) {
    Prod g = (Prod) it.next();
    out.print(g.getId()+"  "+g.getPname()+"</br>");
    }楼上帮忙看看错在那里了!
      

  2.   


    <session-factory>
    <property name="myeclipse.connection.profile">xiaowei</property>
    <property name="connection.url">jdbc:mysql://localhost/xiaowei</property>
    <property name="connection.username">root</property>
    <property name="connection.password">123</property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property><mapping resource="com/xiaowei/Hibernate/Prod.hbm.xml" /></session-factory></hibernate-configuration>这是hibernate.conf.xml代码
    整好几天了,都晕死了!