How to design for JPA in a non-Java EE web server (e.g. Tomcat) -
EntityManager does not have any privacy content available to inject, but you need to manually manage transactions, Is this the best way to design such an application? For EntityManagerFactory / EntityManager, as far as I can see, you must accept an EntityManager in each DAO contractor like
public class DAOImpl DAO {Private unit manager Applies to; DAOImpl (EntityManager em) {this.em = em; } // Follow all CRUD functions}
The first question arises when you EntityManager # close () ?
Point A: By the way I see it, you are doing it better at the end of the request cycle, which means that you associate EntityManager with the existing thread (Use threadlocal?)
The second question is, how and when will you apply antimitagger?
Keeping in mind that where we create and close the unit, we can be as a static method as follows
Public Fixed EntityManager createEntityManager () { Return entityManagerFactory.createEntityManager (PERSISTENT_NAME); }
But since we want to be involved in making the DAO, we are factory like
public category Daphorifier {public stationary Dao Dao (<)
Point A , we should use ThreadLocals to create DAO by using EntityManager for the current thread.
To manage transactions
The way I can think (which imitates JPA space) is to use the reflection to create their own transaction annotations and to initiate the initiation / commit / rollback operation.
You should then manage transactions with defrinters
I do not have all this Why do you try to make the whole JPA device yourself? You should be able to use JPA without the container
Spring can help you with this. Try it
Comments
Post a Comment