Please Help: Below error when I tried to add details to tables using hibernate:
Code:
java.lang.NullPointerException
org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.nextTimestamp(RegionFactoryCacheProviderBridge.java:93)
org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:639)
org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:648)
com.package1.service.AuthenticateUser.addUser(AuthenticateUser.java:32)
com.package1.controllers.LoginServlet.doPost(LoginServlet.java:68)
LoginServletCode:
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String username = request.getParameter("user");
String password = request.getParameter("pass");
response.setContentType("text/html");
String result = authenticateUser.authenticateUser(username, password);
if (result == "SUCCESS") {
RequestDispatcher rqdpr = request.getRequestDispatcher("Success.jsp");
rqdpr.forward(request, response);
}else {
//response.sendRedirect("Register.jsp");
authenticateUser.addUser("abcdef", "abcdef","abcdef", "abcdef"); //Line: 68
}
}
private AuthenticateUser authenticateUser = new AuthenticateUser();
}
AuthenticateUserCode:
public class AuthenticateUser {
public String authenticateUser(String username, String password) {
Session session = factory.openSession();
Transaction txn = session.getTransaction();
String usernamefromdb = user.getName();
String passwordfromdb = user.getPassword();
try {
if (username.equals(usernamefromdb)
&& password.equals(passwordfromdb)) {
return "SUCCESS";
} else {
return "FAILURE";
}
} finally {
factory.close();
}
}
public void addUser(String uname, String uemail, String usrnme,
String upass) {
Session session = factory.openSession(); // Line 32
Transaction txn = session.beginTransaction();
user.setName(uname);
user.setEmail(uemail);
user.setUsrname(usrnme);
user.setPassword(upass);
txn.commit();
session.save(user);
session.close();
factory.close();
}
private static SessionFactory factory = HibernateSessionManager
.getSessionFactory();
private User user = new User();
}