title: No transaction starts within Spring @Transactional method
body: <p>I run into strange problem while developing application using Spring (3.0.5), Hibernate (3.6.0) and Wicket (1.4.14). The problem is: i cannot save or modify any object into database. By 'cannot' I mean that all changes in object or calls to EntityManager.persist(foo) are simply, silently ignored. Selects work.</p>
  
  <p>Sample case is simple - on some wicket page i try to save object into database, like follows</p>
  
  <pre><code>public class ComicDetailsPage extends PublicBasePage {
  
  @Override
  protected void onConfigure() {
      System.out.println("In onConfigure");
      super.onConfigure();
      comicDAO.insert("abc");
  
  }
  
  @SpringBean(name="comicDAO")
  private ComicDAO comicDAO;
  
      (....)
  </code></pre>
  
  <p>Here is comicDAO</p>
  
  <pre><code>@Service
  public class ComicDAO {
  
  @PersistenceContext
  private EntityManager em;
  
  (...)
  
  @Transactional
  public void insert(String title) {
      Comic c = new Comic();
      c.setTitle(title);
      em.persist(c);
  }
  
  @Transactional
  public Comic add1toTitle(int pk) {
      System.out.println("Beginning fetching");
      Comic c = em.find(Comic.class, pk);
      System.out.println("Fetched updating");
      c.setTitle(c.getTitle()+"1");
      System.out.println("Updated persisting");
      em.persist(c);
      System.out.println("Persisted returning");
      return c;
  }
  </code></pre>
  
  <p>I turned on logging and here is relevant part of logs (both Hibernate and Spring are set to TRACE). I added ** to lines I think are important here.</p>
  
  <pre><code>In onConfigure
  01:53:19.330 [qtp2119047503-15] DEBUG o.s.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'txManager'
  **01:53:19.330 [qtp2119047503-15] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 13006687993**
  **01:53:19.330 [qtp2119047503-15] DEBUG org.hibernate.transaction.JDBCTransaction - begin**
  01:53:19.330 [qtp2119047503-15] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
  01:53:19.335 [qtp2119047503-15] DEBUG org.hibernate.transaction.JDBCTransaction - current autocommit status: true
  01:53:19.335 [qtp2119047503-15] DEBUG org.hibernate.transaction.JDBCTransaction - disabling autocommit
  01:53:19.336 [qtp2119047503-15] TRACE org.hibernate.jdbc.JDBCContext - after transaction begin
  01:53:19.336 [qtp2119047503-15] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 13006687993
  01:53:19.336 [qtp2119047503-15] TRACE org.hibernate.impl.SessionImpl - setting flush mode to: AUTO
  01:53:19.336 [qtp2119047503-15] TRACE org.hibernate.impl.SessionImpl - setting cache mode to: NORMAL
  01:53:19.337 [qtp2119047503-15] TRACE org.hibernate.engine.IdentifierValue - id unsaved-value: 0
  01:53:19.337 [qtp2119047503-15] TRACE org.hibernate.event.def.AbstractSaveEventListener - transient instance of: pl.m4ks.comics.entity.Comic
  01:53:19.337 [qtp2119047503-15] TRACE org.hibernate.event.def.DefaultPersistEventListener - saving transient instance
  **01:53:19.338 [qtp2119047503-15] TRACE org.hibernate.event.def.AbstractSaveEventListener - saving [pl.m4ks.comics.entity.Comic#&lt;null&gt;]**
  **01:53:19.341 [qtp2119047503-15] DEBUG org.hibernate.event.def.AbstractSaveEventListener - delaying identity-insert due to no transaction in progress**
  01:53:19.341 [qtp2119047503-15] TRACE org.hibernate.impl.SessionImpl - closing session
  01:53:19.341 [qtp2119047503-15] TRACE org.hibernate.jdbc.ConnectionManager - connection already null in cleanup : no action
  01:53:19.341 [qtp2119047503-15] DEBUG org.hibernate.transaction.JDBCTransaction - commit
  **01:53:19.341 [qtp2119047503-15] TRACE org.hibernate.impl.SessionImpl - automatically flushing session**
  01:53:19.341 [qtp2119047503-15] TRACE org.hibernate.jdbc.JDBCContext - before transaction completion
  01:53:19.341 [qtp2119047503-15] TRACE org.hibernate.impl.SessionImpl - before transaction completion
  01:53:19.342 [qtp2119047503-15] DEBUG org.hibernate.transaction.JDBCTransaction - re-enabling autocommit
  01:53:19.342 [qtp2119047503-15] DEBUG org.hibernate.transaction.JDBCTransaction - committed JDBC Connection
  01:53:19.342 [qtp2119047503-15] TRACE org.hibernate.jdbc.JDBCContext - after transaction completion
  01:53:19.342 [qtp2119047503-15] DEBUG org.hibernate.jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
  01:53:19.342 [qtp2119047503-15] TRACE org.hibernate.impl.SessionImpl - after transaction completion
  01:53:19.342 [qtp2119047503-15] TRACE org.hibernate.impl.SessionImpl - closing session
  01:53:19.342 [qtp2119047503-15] TRACE org.hibernate.jdbc.ConnectionManager - performing cleanup
  01:53:19.342 [qtp2119047503-15] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
  01:53:19.342 [qtp2119047503-15] TRACE org.hibernate.jdbc.JDBCContext - after transaction completion
  01:53:19.342 [qtp2119047503-15] DEBUG org.hibernate.jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
  01:53:19.342 [qtp2119047503-15] TRACE org.hibernate.impl.SessionImpl - after transaction completion
  </code></pre>
  
  <p>Of course No object is saved into database. </p>
  
  <p>The last file - my applicationCOntext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans (...)&gt;
  
      &lt;context:component-scan base-package="pl.m4ks.comics"/&gt;
      &lt;context:annotation-config /&gt; 
  
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"&gt;
          &lt;property name="driverClass" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:8889/comics" /&gt;
          &lt;property name="username" value="root"/&gt;
          &lt;property name="password" value="root" /&gt;          
      &lt;/bean&gt;
  
      &lt;bean id="entityManagerFactory"
            class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="main" /&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
           &lt;property name="dataSource"&gt;
              &lt;ref bean="dataSource"/&gt;
          &lt;/property&gt;
          &lt;property name="packagesToScan"&gt;
               &lt;value&gt;pl.m4ks.comics&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory"&gt;
              &lt;ref bean="sessionFactory" /&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;
  
      &lt;tx:annotation-driven transaction-manager="txManager"  proxy-target-class="true"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>I have no idea what can be the problem and how to solve it. I don't want to manage transaction in my code - this is what Spring is for. </p>