Hello everyone, I tried to create a project in which you can create an account for yourself and then implement all possible CRUD operations on the Product class that is mapped to the product table. But here is one problem, the security part works with a bang, but here the STEAD part of the application gives the error HibernateException: No Session found for current thread. Help me figure out why she appeared, because I already have no options. And @Transactional is in service over all the methods that apply to dao and it seems to have done everything right in the hml, but still gives me this error. Also, if you need to clarify something, ask, I will answer with pleasure.

Technologies I used: Spring Security | MVC, Hibernate, Postgresql, Maven, JSP
Link to git https://github.com/Dimassss/SpringSite/tree/my_site

    1 answer 1

    Do something like this in the mvc.xml setup

    <tx:annotation-driven transaction-manager="transactionalManagerLocalDb"/> <bean id="dataSourceLocalDb" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.postgresql.Driver"/> <property name="url"> <value>jdbc:postgresql://localhost:5432/abonents?useUnicode=true&amp;characterEncoding=UTF-8&amp;characterSetResults=UTF-8</value> </property> <property name="username" value="postgres"/> <property name="password" value="user"/> <bean id="sessionFactoryLocalDb" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSourceLocalDb"/> <property name="packagesToScan" value="com.springapp.mvc.models_local_db"/> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.c3p0.acquire_increment">1</prop> <prop key="hibernate.c3p0.max_size">15</prop> <prop key="hibernate.c3p0.min_size">5</prop> <prop key="hibernate.c3p0.timeout">1800</prop> <prop key="hibernate.c3p0.max_statements">0</prop> </props> </property> </bean> <bean id="transactionalManagerLocalDb" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactoryLocalDb"/> </bean> 

    use in java code

     @Autowired @Qualifier(value = "sessionFactoryLocalDb") SessionFactory sessionFactoryLocalDb; public Success onAdd(Abonent abonent){ if(abonent!=null){ sessionFactoryLocalDb.getCurrentSession().save(abonent); success.setResult(200); return success; } success.setResult(100); return success; } 
    • I plow all. - EmErIx_007
    • Works! Thank you very much, if it were not for you, then I would have sat, I don’t know what to do)) - Dimas Karpus