-1

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?

user5620472
  • 2,722
  • 8
  • 44
  • 97

1 Answers1

1

Have you checked the log ? The BaseJpaDao does not seems to have a public empty constructor, so there should be an error in karaf.log saying the the baseDaobean cannot be created...

Alexandre Cartapanis
  • 1,513
  • 3
  • 15
  • 19