I'm Spring and Hibernate newbie. I've created the entity User and DAO - UserHibernateDao. I want to test how the hibernate working in simple java-class with public static void main:
public class Starter {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("/org/jtalks/jcommune/model/entity/applicationContext-dao.xml");
Dao<User> uhd = (Dao) context.getBean("userDao");
User user = new User();
user.setNickName("UserName");
uhd.saveOrUpdate(user);
}
}
but I get the error
INFO: Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@17b4703] of Hibernate SessionFactory for HibernateTransactionManager Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystemException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)
I understand I need to create something like session and transaction but I don't know how exactly I should do this.
my config User.java UserHibernateDao.java Full Project
Thanks