Guest User

Untitled

a guest
Nov 29th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. private static SessionFactory getSessionFactory() {
  2. Configuration configuration = new Configuration();
  3. configuration.setProperty("connection.driver_class",
  4. "com.mysql.jdbc.Driver");
  5. configuration.setProperty("hibernate.connection.url",
  6. "jdbc:mysql://localhost:3306/my_test?useUnicode=true&zeroDateTimeBehavior=convertToNull&characterEncoding=utf8");
  7. configuration.setProperty("hibernate.connection.username", "username");
  8. configuration.setProperty("hibernate.connection.password", "password");
  9. configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
  10. ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
  11. configuration.getProperties()).build();
  12. SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
  13. return sessionFactory;
  14. }
  15.  
  16. private Session getCurrentSession() {
  17. return getSessionFactory().getCurrentSession();
  18. }
  19.  
  20. private Criteria createCriteria() {
  21. return getCurrentSession().createCriteria(SomeClass.class);
  22. }
  23.  
  24. private List<TaskEntityMock> listTaks(){
  25. return createCriteria().list();
  26. }
  27.  
  28. org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: No CurrentSessionContext configured!
  29. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
  30. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
  31. javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
  32. org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
  33. javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
  34. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  35. org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
Add Comment
Please, Sign In to add comment