If you try to get a connection from the entitymanager
((SessionImpl)entityManager.getDelegate()).connection();
and still get an exception as below
Servlet.service() for servlet dispatcher threw exception: org.hibernate.SessionException: Session is closed!
then try to use like the below one to get the connection and dont forget to wrap up the method with @Transactional or open a transaction from a session.
@PersistenceContext
private EntityManager entityManager;
Session session = entityManager.unwrap(Session.class);
SessionImplementor sessionImplementor = (SessionImplementor) session;
Connection cc = sessionImplementor.getJdbcConnectionAccess().obtainConnection();
((SessionImpl)entityManager.getDelegate()).connection();
and still get an exception as below
Servlet.service() for servlet dispatcher threw exception: org.hibernate.SessionException: Session is closed!
then try to use like the below one to get the connection and dont forget to wrap up the method with @Transactional or open a transaction from a session.
@PersistenceContext
private EntityManager entityManager;
Session session = entityManager.unwrap(Session.class);
SessionImplementor sessionImplementor = (SessionImplementor) session;
Connection cc = sessionImplementor.getJdbcConnectionAccess().obtainConnection();
No comments:
Post a Comment