Hi there. I am junion developer, do not judge me harshly. I am using Hibernate 5.0.3 and Spring 4.2.2. For transactions i am using Spring Transactions. I have exeption when trying to save dates to db.
java.lang.ClassNotFoundException: org.hibernate.engine.transaction.spi.TransactionContextI`m trying solve this problev many days. And i can`t understand what i am doing wrong.
Thanks.
This is my
Configuration class:Code:
@Configuration
@EnableTransactionManagement
public class Confuguration {
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setConfigLocation(new ClassPathResource("hibernate.cfg.xml"));
return sessionFactory;
}
@Bean
@Autowired
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
return new PersistenceExceptionTranslationPostProcessor();
}
}
hibernate.cfg.xml:Code:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test_db?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">test_db</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.connection.pool_size">20</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<mapping class="com.korablev.entities.PeopleEntity"/>
</session-factory>
</hibernate-configuration>
DAO:Code:
@Component
public class PeopleDAO {
SessionFactory sessionFacrory;
@Autowired
public PeopleDAO(SessionFactory sessionFacrory){
this.sessionFacrory = sessionFacrory;
}
@Transactional
public void addPeople(PeopleEntity p){
Session session = sessionFacrory.getCurrentSession();
session.saveOrUpdate(p);
}
}
And Controller:Code:
@Autowired
PeopleEntity people;
@Autowired
PeopleDAO peopleDao;
@RequestMapping(value = "/add-people",method = RequestMethod.GET)
public String gotToPeopleForm(Model model){
people.setName("Name");
people.setSurname("Surname");
peopleDao.addPeople(people);
return "redirect:/";
}