1
votes

I was looking for documentation about how to configure spring LocalContainerEntityManagerFactory where it can use multiple persistence unit from persistence.xml. I want to use jndi datasource. Also if possible I would like to use server managed entity factory instead of localcontainerentitymanagerfactory using

<jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence-units/pu1"/>

Can somebody guide me to the right direction about this configuration? Also I want to inject entitymanager in my dao class using @PersistenceContext

1

1 Answers

0
votes

I don't think that it's possible to do what you want. Each EntityManager is tied to one (and only one) persistance unit, so if you want to use N persistance units, you'll need to instanciate N EntityManagerFactory's.

The "problem" of doing this, is that then, you'll need to annotate every usage of EntityManager with @PersistenceContext and specify which entity manager you want to use.