1

As soon as I enter into my transational method i am not getting the below lines in my log

"2018-04-24 12:44:02,545 [http-nio-8080-exec-6] DEBUG org.hibernate.internal.SessionImpl.<init> 243  - Opened session at timestamp: 15245540425
""2018-04-24 12:44:02,546 [http-nio-8080-exec-6] DEBUG o.h.e.t.spi.AbstractTransactionImpl.begin 158  - begin
""2018-04-24 12:44:02,546 [http-nio-8080-exec-6] DEBUG o.h.e.j.i.LogicalConnectionImpl.obtainConnection 295  - Obtaining JDBC connection
""2018-04-24 12:44:02,546 [http-nio-8080-exec-6] DEBUG o.h.e.j.i.LogicalConnectionImpl.obtainConnection 301  - Obtained JDBC connection
""2018-04-24 12:44:02,546 [http-nio-8080-exec-6] DEBUG o.h.e.t.i.jdbc.JdbcTransaction.doBegin 69  - initial autocommit status: true
""2018-04-24 12:44:02,546 [http-nio-8080-exec-6] DEBUG o.h.e.t.i.jdbc.JdbcTransaction.doBegin 71  - disabling autocommit

I am expecting above log.but it is starting session only after calling dao method.

XtremeBaumer
  • 6,275
  • 3
  • 19
  • 65
abhinav
  • 29
  • 1
  • **Why** would you expect that log? – XtremeBaumer Apr 24 '18 at 08:38
  • as soon as we enter a method which is annotated with @transactional then 1)Session would Start 2)Transaction would begin.In my case session is starting ,but it is started in my DAO and transaction is not event starting – abhinav Apr 24 '18 at 08:40
  • `2018-04-24 12:44:02,546 [http-nio-8080-exec-6] DEBUG o.h.e.t.spi.AbstractTransactionImpl.begin 158 - begin` your transaction does start... Maybe you should read [this answer](https://stackoverflow.com/a/24713402/7109162) – XtremeBaumer Apr 24 '18 at 08:46
  • thats what i am saying iam expecting this log which begins transaction.But in my case the log doesnt begin the transaction – abhinav Apr 24 '18 at 08:47
  • Then you should also post what you actually get – XtremeBaumer Apr 24 '18 at 08:47
  • @abhinav Actually, when a business transaction is begun by invoking a Transactional annotated method, then hibernate session is created (a TransactionManager may delay the actual creation until the session is first used). Once that method completes, the business transaction is committed or rolled back, which closes the hibernate session. You can also refer this Q&A here. I found it helpful. https://stackoverflow.com/questions/24710620/how-does-transactional-influence-current-session-in-hibernate – Gautam Tyagi Nov 17 '19 at 13:38

1 Answers1

0
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean>

Firstly check the proper Hibernate version in this tag.

Secondly , what needs to be done is to remove from the applicationContext.xml file the following line for Hibernate properties:

<prop key="hibernate.current_session_context_class">thread</prop>

Once that is remove, Hibernate makes use of Spring for transaction management