-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate 5 + Spring Transaction
PostPosted: Tue Nov 17, 2015 7:29 am 
Newbie

Joined: Tue Nov 17, 2015 7:09 am
Posts: 1
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.TransactionContext
I`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:/";
    }


Top
 Profile  
 
 Post subject: Re: Hibernate 5 + Spring Transaction
PostPosted: Wed Nov 18, 2015 8:26 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Increase the version of spring, and use the classes of the package org.springframework.orm.hibernate5


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.