I tried create BaseDao and inject EntityManager to it. In Spring I was make this:
public abstract class BaseJpaDao<E> implements BaseDao<E>{
protected Class<?> entityClass;
@PersistenceContext(unitName = "access")
protected EntityManager entityManager;
public BaseJpaDao(Class<?> entityClass) {
this.entityClass = entityClass;
}
@Override
public E persist(E e) {
entityManager.persist(e);
return e;
}
but now I tried make this in OSGI and I not understand how do it. I treid write in blueprint.xml
<bean id="baseJpaDao" class="domain.access.impl.BaseJpaDao" >
<jpa:context unitname="access" property="entityManager"/>
<tx:transaction method="*" value="RequiresNew"/>
</bean>
and after this
public abstract class BaseJpaDao<E> implements BaseDao<E>{
protected Class<?> entityClass;
private EntityManager entityManager;
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public BaseJpaDao(Class<?> entityClass) {
this.entityClass = entityClass;
}
@Override
public E persist(E e) {
entityManager.persist(e);
return e;
}
I treid like this link
but not help.
I tried this
EntityManagerFactory emf = Persistence.createEntityManagerFactory("access", System.getProperties());
em = emf.createEntityManager();
but not help.