Hi,
   I am looking for is some usage examples of session-per-thread model in a
JSE environment while using JPA in Spring Framework environment.

To elaborate the requirements:

1. Must use ApplicationContext in a JSE environment (not
WebApplicationContext)

2. A pair of Spring Beans B1, B2 each scoped as 'prototype' is injected with 
    @PersistenceContext EntityManager em;

3. This is the implementation of B1:
    public class B1 {
    @PersistenceContext EntityManager em;
    
    @Transactional
    public EntityManager getEntityManager() {
       return em;
    }
 
   Same is B2.

4. Now, by session-per-thread model, I mean, the following assertion must
satisfy when called from the same thread:
     // call B1, B2 from same thread
      EntityManager em1 = b1.getEntityManager();
      EntityManager em2 = b2.getEntityManager();
  
     assert em1 == em2;
     assert em1.getDelegate() == em2.getDelegate();

     Interestingly, I am seeing the first assertion pass but the second
fail. While what I want is the second assertion to pass because em1, em2 are
mere proxy while em1.getDelegate() is the actual OpenJPA EntityManager.

5. The application context uses 
       org.springframework.orm.jpa.JpaTransactionManager
and  org.springframework.orm.jpa.LocalEntityManagerFactoryBean.


Question:
  1. Is it possible to do get such a session-per-thread model via Spring
configuration only or one must develop some custom code?

 2. Can someone point me to code samples where similar session-per-thread
model is attempted?

 3. A TransactionSynchronizationManager exists in Spring codebase ...  that
seems to address the issue of binding a resource with a key -- any pointer
to its usage?

  Thanks in advance --
-- 
View this message in context: 
http://www.nabble.com/How-to-configure-Spring-JPA-for-Session-per-thread-model--tp17615111p17615111.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to