public void testSessionStarting_Pc_ParentPc() { MockFlowSession parentSession = newFlowSession(true, null); MockFlowSession childSession = newFlowSession(true, parentSession); getListener().sessionStarting(new MockRequestContext(), parentSession, null); assertSessionBound(); assertSessionInScope(parentSession); getListener().sessionStarting(new MockRequestContext(), childSession, null); assertSessionBound(); assertSessionInScope(childSession); assertSame("Parent PersistenceContext should be re-used", parentSession.getScope().get("persistenceContext"), childSession.getScope().get("persistenceContext")); }
public void testSameSession() { MockRequestContext context = new MockRequestContext(); MockFlowSession flowSession = new MockFlowSession(); flowSession.getDefinition().getAttributes().put("persistenceContext", "true"); hibernateListener.sessionStarting(context, flowSession, null); context.setActiveSession(flowSession); assertSessionBound(); // Session created and bound to conversation final Session hibSession = (Session) flowSession.getScope().get("persistenceContext"); assertNotNull("Should have been populated", hibSession); hibernateListener.paused(context); assertSessionNotBound(); // Session bound to thread local variable hibernateListener.resuming(context); assertSessionBound(); hibernate.templateExecuteWithNativeSession(session -> assertSame("Should have been original instance", hibSession, session)); hibernateListener.paused(context); assertSessionNotBound(); }