hibernate-reactive icon indicating copy to clipboard operation
hibernate-reactive copied to clipboard

Method for detecting if Session is open?

Open noobgramming opened this issue 1 year ago • 1 comments

Hello! I'm writing some DAO-like code and want to ensure a Session is already open when it's called. But Hibernate Reactive doesn't expose a getCurrentSession() on SessionFactory

Mutiny SessionFactory already checks for this internally, but doesn't expose access

Mutiny Code:

		Mutiny.Session current = context.get( contextKeyForSession );
		if ( current != null && current.isOpen() ) {
			LOG.debug( "Reusing existing open Mutiny.Session which was found in the current Vert.x context" );
			return work.apply( current );
		}
		else {
			LOG.debug( "No existing open Mutiny.Session was found in the current Vert.x context: opening a new instance" );
			return withSession( openSession(), work, contextKeyForSession );
		}

Can we add something that allows you to fetch current session (if one is in progress), or at least check if a Session is already open?

noobgramming avatar Oct 26 '23 15:10 noobgramming

You can just call withSession(). Please refer to the Javadoc:

		/**
		 * Perform work using a {@link Session reactive session}.
		 * <p>
		 * <il>
		 * <li>If there is already a session associated with the current
		 * reactive stream, then the work will be executed using that
		 * session.
		 * <li>Otherwise, if there is no session associated with the
		 * current stream, a new session will be created.
		 * </il>
		 * <p>

gavinking avatar Oct 27 '23 10:10 gavinking