I use karaf 4.0.5
and hibernate 4.2.15
And I want get EntityManager
in my BaseDao class.
If I tried get EntityManager
in my service
<bean id="subscriberService" class="domain.payment.impl.subscriber.SubscriberServiceImpl" scope="singleton"
init-method="init">
<tx:transaction method="*" />
</bean>
and in class
@PersistenceContext(unitName="payment")
private EntityManager entityManager;
I get EntityManager normaly.
But if I tried it in another class
public class BaseJpaDao<E> implements BaseDao<E>{
protected Class<?> entityClass;
@PersistenceContext(unitName="payment")
private EntityManager entityManager;
public BaseJpaDao(Class<?> entityClass) {
this.entityClass = entityClass;
}
@Override
public E persist(E e) {
entityManager.persist(e);
return e;
}
My entityManager
is NULL;
I tried
<bean id="baseDao" class="domain.payment.impl.base.BaseJpaDao" scope="singleton"
init-method="init">
<tx:transaction method="*" />
</bean>
But it not help.
In Spring project it work fine, but in OSGi I have many problems.
really only from the services I can get entityManager
?