Conversations with (Shared web hosting) JPA 11.3 Conversations with JPA We

Conversations with JPA 11.3 Conversations with JPA We now look at persistence context propagation and conversation implementation with JPA and EJB 3.0. Just as with native Hibernate, you must consider three points when you want to implement conversations with Java Persistence: You want to propagate the persistence context so that one persistence context is used for all data access in a particular request. In Hibernate, this functionality is built in with the getCurrentSession() feature. JPA doesn t have this feature if it s deployed stand-alone in Java SE. On the other hand, thanks to the EJB 3.0 programming model and the well-defined scope and lifecycle of transactions and managed components, JPA in combination with EJBs is much more powerful than native Hibernate. If you decide to use a detached objects approach as your conversation implementation strategy, you need to make changes to detached objects persistent. Hibernate offers reattachment and merging; JPA only supports merging. We discussed the differences in the previous chapter in detail, but we want to revisit it briefly with more realistic conversation examples. If you decide to use the session-per-conversation approach as your conversation implementation strategy, you need to extend the persistence context to span a whole conversation. We look at the JPA persistence context scopes and explore how you can implement extended persistence contexts with JPA in Java SE and with EJB components. Note that we again have to deal with JPA in two different environments: in plain Java SE and with EJBs in a Java EE environment. You may be more interested in one or the other when you read this section. We previously approached the subject of conversations with Hibernate by first talking about context propagation and then discussing long conversations. With JPA and EJB 3.0, we ll explore both at the same time, but in separate sections for Java SE and Java EE. We first implement conversations with JPA in a Java SE application without any managed components or container. We re often going to refer to the differences between native Hibernate conversations, so make sure you understood the previous sections of this chapter. Let s discuss the three issues we identified earlier: persistence context propagation, merging of detached instances, and extended persistence contexts.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Leave a Reply