我正在从JSP页面传递数据并将其保存在数据库中。所有值都已正确存储在数据库中。但是,我的控制台和UI出现错误。
堆栈跟踪:
Jun 25, 2018 8:13:02 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/IEFMSystem] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Session/EntityManager is closed] with root cause
java.lang.IllegalStateException: Session/EntityManager is closed
at org.hibernate.internal.AbstractSharedSessionContract.checkOpen(AbstractSharedSessionContract.java:357)
at org.hibernate.engine.spi.SharedSessionContractImplementor.checkOpen(SharedSessionContractImplementor.java:138)
at org.hibernate.internal.AbstractSharedSessionContract.checkOpenOrWaitingForAutoClose(AbstractSharedSessionContract.java:363)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1254)
at org.hibernate.internal.SessionImpl.access$1900(SessionImpl.java:207)
DAOImpl类中的方法-
@Override public void addNewContributorMethod(User user){
userFactory = new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(User.class)
.buildSessionFactory();
Session userSession = userFactory.getCurrentSession();
try
{
System.out.println("Inside addNewContributorMethod of DAO");
// start a transaction
userSession.beginTransaction();
// save the student object
System.out.println("Saving the student..." + " User Id: " + user.getUserId() + " User Name: " + user.getUserName());
userSession.save(user);
System.out.println(user);
// commit transaction
try
{
userSession.getTransaction().commit();
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println(userSession.get(User.class, user.getUserId()));
System.out.println("Done!");
}
finally
{
System.out.println("In Finally");
//userSession.close();
//userFactory.close();
}
}