Skip to main content

[jsr338-experts] Re: Inheritance of Extended Persistence Context

  • From: Scott Marlow <smarlow@...>
  • To: michael keith <michael.keith@...>
  • Cc: jsr338-experts@...
  • Subject: [jsr338-experts] Re: Inheritance of Extended Persistence Context
  • Date: Fri, 01 Jun 2012 13:00:56 -0400

On 06/01/2012 12:25 PM, michael keith wrote:
Assuming the DAO interface is local and does not have a @Remote on it,
and also assuming that there is just a forgotten injection annotation of
@PersistenceContext(type=PersistenceContextType.EXTENDED) on the EM in
TestService, then the PC should be inherited by both SFSBs DAO1 and
DAO2. If the session beans are local then you should not leave the EJB
container instance.
(Does that answer the question?)

I think that you have answered my question about whether the beans would be in the same EJB container instance. I don't think there will be disagreement about that.

Regarding whether applications can portably expect the same behaviour for this case is my other concern. We purposely are not specifying @PersistenceContext(type=PersistenceContextType.EXTENDED) on the EM in TestService to drive this discussion.

I think the current 7.6.3.1 wording is not clear enough about whether the extended persistence context inheritance will occur between the beans executing in the same EJB container instance.

I think that different vendors are handling this differently, which impacts EE portability (IMO). I think that some vendors will inherit the extended persistence context only if the beans parent (recursively up to the top level bean) has the same persistence context. Other vendors will inherit the extended persistence context only if another bean with the same extended persistence context is executing in the same EJB container instance.

I would like to clarify the intended behaviour that applications should expect, or that it is implementation defined for this case (so application writers can make a choice based on facts.)



On 01/06/2012 11:50 AM, Scott Marlow wrote:
In the interest of ensuring EE application portability, I'd like to
change or add additional wording to the JPA 2.1 "7.6.3.1 Inheritance
of Extended Persistence Context" section.

In the following example, instances of beans TestSFSB, DAO1, DAO2 will
be "executing in the same EJB container instance" (PostConstruct for {
TestSFSB, DAO1, DAO2} should execute in the same EJB container
instance). One question that I have, is there a possibility for {
TestSFSB DAO1, DAO2} to not execute in the same EJB container
instance? Is that EJB container implementation specific?

@Stateful
@Remote(TestService.class)
public class TestSFSB implements TestService {
private EntityManager entityManager;

@EJB(beanName = "DAO1") private DAO dao1;
@EJB(beanName = "DAO2") private DAO dao2;

public String testfunc() {
dao1.myFunction();
dao2.myFunction();
return "fine";
}
}

@Stateful
public class DAO1 implements DAO {
@PersistenceContext(type=PersistenceContextType.EXTENDED)
private EntityManager entityManager;

public void myFunction() {
entityManager.find(PersonOrm.class, 123L);
System.out.println("DAO1:" + entityManager);
}
}

@Stateful
public class DAO2 implements DAO {
@PersistenceContext(type=PersistenceContextType.EXTENDED)
private EntityManager entityManager;

public void myFunction() {
entityManager.find(PersonOrm.class, 123L);
System.out.println("DAO2:" + entityManager);
}
}


Text from the JPA 2.0 specification:

"
7.6.2.1 Inheritance of Extended Persistence Context

If a stateful session bean instantiates a stateful session bean
(executing in the same EJB container instance) which also has such an
extended persistence context, the extended persistence context of the
first stateful session bean is inherited by the second stateful
session bean and bound to it, and this rule recursively
applies—independently of whether transactions are active or not at the
point of the creation of the stateful session beans.
"

Text from the JPA 2.1 specification:

"
7.6.3.1 Inheritance of Extended Persistence Context
If a stateful session bean instantiates a stateful session bean
(executing in the same EJB container instance) which also has such an
extended persistence context with the same synchronization type, the
extended persistence context of the first stateful session bean is
inherited by the second stateful session bean and bound to it, and
this rule recursively applies—independently of whether transactions
are active or not at the point of the creation of the stateful session
beans. If the stateful session beans differ in declared
synchronization type, the EJBException is thrown by the container.
"

Depending on the answer to my first question, I'd like to add
clarifying text (to the JPA 2.1 7.6.3.1 section) that makes it more
obvious whether DAO1 + DAO2 (which could execute in the same EJB
container) will inherit the same extended persistence context. I'll
try to make some suggestions after we have answered these questions as
to whether DAO1 + DAO2 will always execute in the same EJB container.

Scott





[jsr338-experts] Re: Inheritance of Extended Persistence Context

(continued)

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Scott Marlow 06/01/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Linda DeMichiel 06/01/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Scott Marlow 06/07/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Linda DeMichiel 06/18/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Emmanuel Bernard 06/04/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Scott Marlow 06/07/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Werner Keil 06/07/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Scott Marlow 06/11/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Linda DeMichiel 06/18/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Scott Marlow 06/20/2012

[jsr338-experts] Re: Inheritance of Extended Persistence Context

Scott Marlow 06/01/2012
 
 
Close
loading
Please Confirm
Close