Injecting Entitymanager via XML and not annnotations Injecting Entitymanager via XML and not annnotations xml xml

Injecting Entitymanager via XML and not annnotations


Use SharedEntityManagerBean - it creates a shared EntityManager for EntityManagerFactory the same way as @PersistenceContext:

<bean id="itemDaoStore1" class="ItemDaoImpl">     <property name="entityManager">        <bean class = "org.springframework.orm.jpa.support.SharedEntityManagerBean">            <property name = "entityManagerFactory" ref="entityManagerFactory1"/>          </bean>    </property></bean>


You can provide the persistence unit name in the xml configuration, using the SharedEntityManagerBean, like below:

<bean id="testDao" class="com.test.persistence.dao.BaseDAO">    <property name="entityManager">        <bean class="org.springframework.orm.jpa.support.SharedEntityManagerBean">            <property name="persistenceUnitName" value="persistence-test-unit" />        </bean>    </property></bean>

of course, you can have the SharedEntityManagerBean as a separate bean

Here, I m injecting entityManager into BaseDAO as you're doing using @PersistenceContext(unitName="...")