- @PersistenceUnit annotation is used in J5SE applications to handle Java Persistence API (JPA) persistence management. You may use a PeristenceUnit in an application inside a container, but it must be managed by the developer instead of the container.
- @PersistenceContext annotation is used for Container Managed Persistence (CMP). This relieves the developer of having to worry about connection management.
clean & simple
ReplyDeleteThank you
Hi,
ReplyDeleteWe cant use PersistenceContext with Servlets.
Regards,
imran
I am not sure what the issue could be. I have an example which uses both in a servlet. Using the @PersistenceContext requires more work on the part of the developer.
ReplyDeleteRemember @PersistenceUnit uses an EntityManagerFactory, and @PersistenceContext uses an EntityManger.