0

Using Spring 2.0.5

in the dao class

@Repository
@Transactional
public class IsActiveTestDao {
  private EntityManager em;

 public void populateIsActiveTest(){
    Session session = em.unwrap(Session.class);

when I do this or any 50 other ways like:

SessionFactory f = em.unwrap(SessionFactory.class);

I have also tried

em.getDelegate()

I always get a Null Pointer Exception

My question is Can I obtain a hibernate session from a JPA Entity Manager in Spring while using the @Transactional annotation?

0

3 Answers 3

1

You need to add an @Autowired annotation to the EntityManager

Sign up to request clarification or add additional context in comments.

Comments

0

You can use @PersistenceContext annotation to the EntityManager to specify the persistence unit you want to use.

Comments

0

You are creating a null EntityManager. So, you are getting a null pointer exception You need to fetch the EntityManager object from Application context either by

 @PersistenceContext

or

 @Autowired 

to get the initialized object of EntityManager.

Doing this will work for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.