Sunday, October 29, 2006

Persistence Unit or Persistence Context?

Which to use for a particular application depends entirely on the environment, or preference.

  • @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.

3 comments :

Unknown said...

clean & simple

Thank you

imran raza khan said...

Hi,

We cant use PersistenceContext with Servlets.

Regards,
imran

John Yeary said...

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.

Remember @PersistenceUnit uses an EntityManagerFactory, and @PersistenceContext uses an EntityManger.

Popular Posts