Home > Back-end >  Hibernate struts 2 in Java. Lang. NullPointerException
Hibernate struts 2 in Java. Lang. NullPointerException

Time:10-01

First post code
 
Package com. Dao;

Import the Java. Util. List;

The import org. Hibernate. Query;
The import org. Hibernate. Session;
Import org, hibernate SessionFactory;
The import org. Hibernate. Transaction;
The import org. Junit. Test;

The import com. The entity. The Customer;
The import com. Utils. HibernateUtils;

Public class CustomerDaoImpl implements CustomerDao {

@ Override
Public List The.findall () {
SessionFactory SessionFactory=null;
The Session Session=null;
The Transaction tx=null;
Try {
SessionFactory=HibernateUtils. GetSessionFactory ();
The session=sessionFactory. OpenSession ();
Tx=session. BeginTransaction ();

Query Query=session. CreateQuery (" from the Customer ");
List List=query. The list ();
For (c: Customer list) {
Be sad etCustName chtistina georgina rossetti.british poetess System. Out. Println (());
}
Tx.com MIT ();
return list;
} the catch (Exception e) {
Tx. The rollback ();
} the finally {
The session. The close ();
SessionFactory. Close ();
}
return null;
}
}



Said error is in the session. The close (); Out of here, but I this code and I learn hibernate before a project, there can be normal operation

CodePudding user response:

Before the close, and not null judgments
  • Related