Best practice for creating noun.

I use local noun. resource resource with JPA 1. What is the best practice for creating an EntityManager that

  • Create a task to close the entitymanager every time. (Entitymanager is not heavy weight, but still boring)

  • Create an entitymanager for each thread and save it as a ThreadLocal variable and use it (a-where should close the entitymanager b-Any object registered in a bean will be a separate object because the entitymanager whose object in its persistense context is closed or now belongs to another flow.)

  • Store noun person in a bean session and use the same entitymanager during the session (sessions are not familiar with each other)

+4
source share
2 answers

I create an EntityManager for each request and close them in ServletRequestListener .

+3
source

You must enter the EntityManager using the @PersistenceContext annotation. Do not worry about where it came from: - that dependency injection at work.

+5
source

All Articles