20.10. Obtaining an EntityManger
<div class="paragraph">
The easiest, and most supported, method of obtaining an `EntityManager` utilizes OSGi’s `OSGI-INF/blueprint/blueprint.xml` in your bundle.
The container takes the name of your persistence unit, then automatically injects an `EntityManager` instance into your given bean attribute.
</div>
<div class="exampleblock">
<div class="title">Example 492. OSGI-INF/blueprint/blueprint.xml</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight">`<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
default-activation="eager"
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<!-- This gets the container-managed EntityManager and injects it into the DataPointServiceImpl bean.
Assumes DataPointServiceImpl has an "entityManager" field with a getter and setter. -->
<bean id="dpService" class="org.hibernate.osgitest.DataPointServiceImpl">
<jpa:context unitname="managed-jpa" property="entityManager"/>
<tx:transaction method="*" value="Required"/>
</bean>
<service ref="dpService" interface="org.hibernate.osgitest.DataPointService"/>
</blueprint>`</pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect2">