Usually, you can inject a Session to another object ,or you can passing the session as one argument from web application. While, sometime, you may also want to get the session directly from somewhere in java main(string args[]) method, below code should is what you want, enjoy it :)
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
Comments
Post a Comment