Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static SessionFactory getSessionFactory() {
- Configuration configuration = new Configuration();
- configuration.setProperty("connection.driver_class",
- "com.mysql.jdbc.Driver");
- configuration.setProperty("hibernate.connection.url",
- "jdbc:mysql://localhost:3306/my_test?useUnicode=true&zeroDateTimeBehavior=convertToNull&characterEncoding=utf8");
- configuration.setProperty("hibernate.connection.username", "username");
- configuration.setProperty("hibernate.connection.password", "password");
- configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
- ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
- configuration.getProperties()).build();
- SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
- return sessionFactory;
- }
- private Session getCurrentSession() {
- return getSessionFactory().getCurrentSession();
- }
- private Criteria createCriteria() {
- return getCurrentSession().createCriteria(SomeClass.class);
- }
- private List<SomeClass> listTaks(){
- return createCriteria().list();
- }
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: No CurrentSessionContext configured!
- org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
- org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
- javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
- org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
- javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
- org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
- org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
- property name="hibernate.current_session_context_class">thread</property>
- configuration.setProperty("hibernate.current_session_context_class", "thread");
Add Comment
Please, Sign In to add comment