Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
688 views
in Technique[技术] by (71.8m points)

jpa 2.0 - Differences between Container Managed and Application Managed EntityManager

I have a problem to understand the differences between container-managed and application-managed entity manager?

I would be very grateful if you can give me an example that illustrates the differences.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For a container-managed entity manager, the container manages the life-cycle of this entity manager. For an application-managed one, the application (meaning you, the programmer) manages this.

A simple but very visible difference is that you must call close() on an application-managed entity factory. When you use a container-managed one, the container does this for you.

The persistence context of an application-managed entity manager is also not transaction scoped. It starts when the entity manager is created and ends when it is closed. This makes it somewhat like the extended persistence context, with the difference that you can use this type of entity manager everywhere, not just in stateful beans.

Finally, application-managed entity managers are the only ones that can be officially configured to use resource-local transactions, which are independent of any (JTA) transaction the container might have running.

Note that in Java SE you only have application-managed entity managers. So, when you just add Hibernate to Tomcat (a popular combination), you're essentially working with application-managed entity managers all the time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...