title: EntityManager.merge not doing anything
body: <p>I have a User entity:</p>
  
  <pre><code>@Entity
  @Table( name = "bi_user" )
  @SequenceGenerator( name = "USER_SEQ_GEN", sequenceName = "USER_SEQUENCE" )
  public class User
          extends DataObjectAbstract&lt;Long&gt;
  {
      private static final long serialVersionUID = -7870157016168718980L;
  
      /**
       * key for this instance. Should be managed by JPA provider.
       */
      @Id
      @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "USER_SEQ_GEN" )
      private Long key;
  
      /**
       * Username the user will use to login.  This should be an email address
       */
      @Column( nullable=false, unique=true)
      private String username;
  
      // etc. other columns and getters/setters
  }
  </code></pre>
  
  <p>Where DataObjectAbstract is a simple <code>@MappedSuperClass</code> that has a jpa version and equals/hashcode definition.</p>
  
  <p>I have a base dao class that looks like this</p>
  
  <pre><code>public abstract class BaseDaoAbstract&lt;T extends DataObject&lt;K&gt;, K extends Serializable&gt;
          implements BaseDao&lt;T, K&gt;
  {
  
      @PersistenceContext
      private EntityManager em;
  
      /**
       * Save a new entity. If the entity has already been persisted, then merge
       * should be called instead.
       * 
       * @param entity The transient entity to be saved.
       * @return The persisted transient entity.
       */
      @Transactional
      public T persist( T entity )
      {
          em.persist( entity );
          return entity;
      }
  
      /**
       * merge the changes in this detached object into the current persistent
       * context and write through to the database. This should be called to save
       * entities that already exist in the database.
       * 
       * @param entity The entity to be merged
       * @return The merged entity.
       */
      @Transactional
      public T merge( T entity )
      {
          return em.merge( entity );
      }
  
      // other methods like persist, delete, refresh, findByKey that all delegate to em.
  }
  </code></pre>
  
  <p>I have defined the OpenEntityManagerInView filter in web.xml as follows</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;openEntityManagerInViewFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;
          org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
      &lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;entityManagerFactoryBeanName&lt;/param-name&gt;
          &lt;param-value&gt;biEmf&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;openEntityManagerInViewFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>I recently upgrade to eclipselink 2.3.2 and Spring 3.1 and converted from CGLIB proxies to Load Time Weaving with aspectJ for Spring but I did not configure LTW for eclipselink.</p>
  
  <p>The problem is in this code which lives in a spring ApplicationListener, see comments.</p>
  
  <pre><code>        User user = userService.findByKey(userDetails.getKey());
  
          // THIS MERGE NEVER WRITES THROUGH TO THE DATABASE.
          // THIS DOESN'T WORK AS PERSIST EITHER
          user = userService.merge( user.loginSuccess() );
  </code></pre>
  
  <p>user.loginSuccess just sets some fields and returns <code>this</code>  I'm certain it's getting through the code because I get log statements around it and I can set a breakpoint and walk through it.  My postgres log doesn't show any traffic getting to postgres for the merge.</p>
  
  <p>I am saving other stuff all over the place without issue, including users in another location when they change their password, and I know this code used to work.  Is there something obviously amiss here?  Am I using the OpenEntityManagerInViewFilter incorrectly?  Should I need to be in a @Transactional method in order for the entities to be considered managed?  Any help is appreciated.</p>
  
  <p><strong>Update</strong>
  I tried the flush as suggested by prajeesh.  Here's the code</p>
  
  <pre><code>@Transactional
  public T merge( T entity )
  {
      entity = em.merge( entity );
      em.flush();
      return entity;
  }
  </code></pre>
  
  <p>in a class in <code>com.bi.data</code>.  I have this in my spring app config file</p>
  
  <pre><code>&lt;context:component-scan base-package="com.bi.controller,com.bi.data,com.bi.web" /&gt;
  </code></pre>
  
  <p>In my spring configuration I have </p>
  
  <pre><code>&lt;context:load-time-weaver/&gt;
  &lt;tx:annotation-driven mode="aspectj"/&gt;    
  </code></pre>
  
  <p>with an aop.xml that looks like this:</p>
  
  <pre><code>&lt;aspectj&gt;
      &lt;weaver&gt;
          &lt;!-- only weave classes in our application-specific packages --&gt;
          &lt;include within="com.bi..*"/&gt;
      &lt;/weaver&gt;
  &lt;/aspectj&gt;
  </code></pre>
  
  <p>and I got a </p>
  
  <pre><code>javax.persistence.TransactionRequiredException: 
  Exception Description: No transaction is currently active
  </code></pre>
  
  <p>So something is obviously misconfigured, but what?</p>
  
  <p><strong>Update 2:</strong>
  I reverted my changes to enable load time weaving and now the merge goes through with or without the flush, but I still don't understand what the problem is with LTW...</p>