EntityManager and two DAO with PersistenceContextType.EXTENDED

Posted by hsd on Stack Overflow See other posts from Stack Overflow or by hsd
Published on 2011-01-17T16:51:38Z Indexed on 2011/01/17 16:53 UTC
Read the original article Hit count: 310

Filed under:
|
|
|

Hi All,

I have a problem with my entity manager in my application. I have two DAO clasess like this:

@Repository
public abstract class DaoA 
{
    protected ClassA persistentClass;

    @PersistenceContext(name="my.persistence", type=PersistenceContextType.EXTENDED)
    protected EntityManager entityManager;
    -------------- some typical action for DAO --------------
}

Second DAO is for ClassB and looks similar to DaoA. The rest of things are done for me by the Spring framework.

When I'm debugging the application I recognize that both DAO objects have different instances of EntityManager. In the result my two different DAOs are connected with different PersistenceContext.

Question is if this is correct behaviour or not? I would like to have the same PersistenceContext for all my DAO classes. Please give me a hint if this is possible and if I understood the JPA correctly?

Regards Hsd

© Stack Overflow or respective owner

Related posts about spring

Related posts about jpa