title: Injecting the application TransactionManager into a JPA EntityListener
body: <p>I want to use the JPA EntityListener to support spring security ACLs.
  On <code>@PostPersist</code> events, I create a permission corresponding to the persisted entity.</p>
  
  <p>I need this operation to participate to the current Transaction.
  For this to happen I need to have a reference to the application <code>TransactionManager</code> in the <code>EntityListener</code>.</p>
  
  <p>The problem is, Spring can't manage the <code>EntityListener</code> as it is created automatically when <code>EntityManagerFactory</code> is instantiated.
  And in a classic Spring app, the <code>EntityManagerFactory</code> is itself created during the <code>TransactioManager</code> instantiation.</p>
  
  <pre><code>&lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>So I have no way to inject the <code>TransactionManager</code> with the constructor, as it is not yet instantiated.</p>
  
  <p>Making the <code>EntityManager</code> a <code>@Component</code> create another instance of the <code>EntityManager</code>.
  Implementing InitiliazingBean and using <code>afterPropertySet()</code> doesn't work as it's not a Spring managed bean.</p>
  
  <p>Any idea would be helpful as I'm stuck and out of ideas.</p>