So I'm not the only one then.

I just hit another issue at the data access layer/DAOs. According to the OpenJPA docs, the idiomatic design for the data access layer is to use an injectable Entity Manager Factory which provides a fresh Entity Manager each time.

if openjpa.TransactionMode=local, we have to deal with the transactions in the data access layer. But this is not what I want to do - I'd like my 'non-EJB transaction manager of choice' (currently Spring) to manage them.

Or openjpa.TransactionMode=managed allows us to rely on the EntityManagerFactory to retrieve the current Entity Manager for whatever transaction is running - i.e. container-managed transactions.

However in our case it needs to be able to find the Spring transaction manager (or other non-EJB transaction manager) and I've no idea whether it can. Perhaps Spring Frameworks have already coded up a class that provides a static method or a JNDI context where OpenJPA can retrieve the current Entity Manager.

Without anyone else's input on this, I'm going to look further down this route: providing OpenJPA with the means to get at the managed transactions / entity managers.

Do you know whether this is OpenJPA functionality only or if it's specified in the EJB JPA specification? I'd like to be able to say that I can swop OpenJPA for any other JPA provider with only configuration changes necessary.

Regards
Adam

Wes Wannemacher on 10/11/07 18:37, wrote:
Adam,

I'm interested in this as well, I'm trying to build a Struts2 app to
be distributed that provides a "best-practices" example of JPA in
struts2 (a refactoring of the struts-mailreader for those who are
familiar with it). I want to keep Spring out, so I was thinking of
adapting the OpenSessionInView interceptor that people use with
Hibernate.

-Wes

On 11/10/07, Adam Hardy <[EMAIL PROTECTED]> wrote:
I need transactions in my webapp using the OpenSessionInView filter pattern to
enable use of entities in my JSPs.

I am not using an EJB3 container, and I am restricting my use of Spring, or at
least trying to, to the IoC and transaction manager (for XML transaction
configuration).

Is there a recognised JPA mechanism or pattern or an open-source framework for
non-EJB container transactions for this:

(1) servlet filter starts an EntityManager for a thread
(2) stores it in a ThreadLocal
(3) passes it to the transaction manager (Spring at the moment)
(4) lets JSPs run
(5) commits or gets Spring tx manager to commit / rollback etc

I am currently stripping down Spring-web's OpenEntityManagerInViewFilter but if
there is another lightweight transaction framework out there which fits well
with JPA, it'd be preferable.

Reply via email to