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)
source share