@Override public Session openSession() throws HibernateException { return delegate.openSession(); }
public static void inSession(SessionFactoryImplementor sfi, Consumer<SessionImplementor> action) { log.trace( "#inSession(SF,action)" ); try (SessionImplementor session = (SessionImplementor) sfi.openSession()) { log.trace( "Session opened, calling action" ); action.accept( session ); log.trace( "called action" ); } finally { log.trace( "Session closed (AutoCloseable)" ); } }
protected Session openSession() throws HibernateException { session = sessionFactory().openSession(); return session; }
protected Session openSession() throws HibernateException { session = sessionFactory().openSession(); return session; }
private void cleanup() { Session s = sessionFactory().openSession(); s.beginTransaction(); s.createQuery( "delete from VersionedNode where parent is not null" ).executeUpdate(); s.createQuery( "delete from VersionedNode" ).executeUpdate(); s.getTransaction().commit(); s.close(); } }
@After public void after() { Session session = sessionFactory().openSession(); Transaction transaction = session.beginTransaction(); session.createQuery( "delete Question" ).executeUpdate(); session.createQuery( "delete Quizz" ).executeUpdate(); transaction.commit(); session.close(); }
private SharedSessionContractImplementor openTemporarySessionForLoading() { if ( sessionFactoryUuid == null ) { throwLazyInitializationException( "SessionFactory UUID not known to create temporary Session for loading" ); } final SessionFactoryImplementor sf = (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.getSessionFactory( sessionFactoryUuid ); final SharedSessionContractImplementor session = (SharedSessionContractImplementor) sf.openSession(); session.getPersistenceContext().setDefaultReadOnly( true ); session.setFlushMode( FlushMode.MANUAL ); return session; }
@After public void after() { Session s = sessionFactory().openSession(); s.beginTransaction(); s.createQuery( "delete LocalLineItem" ).executeUpdate(); s.createQuery( "delete LocalOrder" ).executeUpdate(); s.getTransaction().commit(); s.close(); }
@Test public void testClose() { final Session session = sessionFactory().openSession(); // 1st call - should be ok session.close(); try { // 2nd should fail (JPA compliance enabled) session.close(); fail(); } catch (IllegalStateException expected) { // expected outcome } } }
@Test public void testQuerySetMaxResults() { final Session session = sessionFactory().openSession(); final Query qry = session.createQuery( "select i from Item i" ); session.close(); assertThat( session.isOpen(), CoreMatchers.is ( false ) ); try { qry.setMaxResults( 1 ); fail( "Expecting call to fail" ); } catch (IllegalStateException expected) { } } @Test
@After public void cleanupData() { super.cleanupCache(); Session s = sessionFactory().openSession(); s.beginTransaction(); s.createQuery( "delete NaturalIdOnManyToOne" ).executeUpdate(); s.createQuery( "delete Citizen" ).executeUpdate(); s.createQuery( "delete State" ).executeUpdate(); s.getTransaction().commit(); s.close(); }
@After public void cleanupData() { super.cleanupCache(); Session s = sessionFactory().openSession(); s.beginTransaction(); s.createQuery( "delete NaturalIdOnManyToOne" ).executeUpdate(); s.createQuery( "delete Citizen" ).executeUpdate(); s.createQuery( "delete State" ).executeUpdate(); s.getTransaction().commit(); s.close(); }
@Test public void testQuerySetFirstResult() { final Session session = sessionFactory().openSession(); final Query qry = session.createQuery( "select i from Item i" ); session.close(); assertThat( session.isOpen(), CoreMatchers.is ( false ) ); try { qry.setFirstResult( 1 ); fail( "Expecting call to fail" ); } catch (IllegalStateException expected) { } }
@Test public void testQuerySetPositionalParameter() { final Session session = sessionFactory().openSession(); final Query qry = session.createQuery( "select i from Item i where i.id = ?1" ); session.close(); assertThat( session.isOpen(), CoreMatchers.is ( false ) ); try { qry.setParameter( 1, 1 ); fail( "Expecting call to fail" ); } catch (IllegalStateException expected) { } }
@Test public void testQuerySetNamedParameter() { final Session session = sessionFactory().openSession(); final Query qry = session.createQuery( "select i from Item i where i.id = :id" ); session.close(); assertThat( session.isOpen(), CoreMatchers.is ( false ) ); try { qry.setParameter( "id", 1 ); fail( "Expecting call to fail" ); } catch (IllegalStateException expected) { } }
@Before public void before() { Session s = sessionFactory().openSession(); s.beginTransaction(); LocalOrder localOrder = new LocalOrder(); localOrder.makeLineItem( "Shoes" ); localOrder.makeLineItem( "Socks" ); s.save( localOrder ); s.getTransaction().commit(); s.close(); }
@Before public void createTestData() { Session session = sessionFactory().openSession(); session.beginTransaction(); try { entity = new A(); session.persist( entity ); } finally { session.getTransaction().commit(); session.close(); } }
private SharedSessionContractImplementor openTemporarySessionForLoading(LazyInitializationWork lazyInitializationWork) { if ( consumer.getSessionFactoryUuid() == null ) { throwLazyInitializationException( Cause.NO_SF_UUID, lazyInitializationWork ); } final SessionFactoryImplementor sf = (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.getSessionFactory( consumer.getSessionFactoryUuid() ); final SharedSessionContractImplementor session = (SharedSessionContractImplementor) sf.openSession(); session.getPersistenceContext().setDefaultReadOnly( true ); session.setHibernateFlushMode( FlushMode.MANUAL ); return session; } }
@Before public void before() { Session session = sessionFactory().openSession(); Transaction transaction = session.beginTransaction(); try { Quizz quizz = new Quizz( 1 ); session.persist( quizz ); quizz.addQuestion( new Question( 1, "question 1" ) ); quizz.addQuestion( new Question( 2, "question 2" ) ); quizz.addQuestion( new Question( 3, "question 3" ) ); transaction.commit(); } finally { session.close(); } }
private Componentizable setupComponentData() throws SQLException { Session session = sessionFactory().openSession(); session.beginTransaction(); Componentizable c = new Componentizable(); c.setNickName( "Flacky" ); Component component = new Component(); component.setName("flakky comp"); SubComponent subComponent = new SubComponent(); subComponent.setSubName("subway"); component.setSubComponent( subComponent ); c.setComponent( component ); session.save( c ); session.getTransaction().commit(); session.clear(); return c; }