/** * Close the open session (stateful or otherwise). */ public void close() { if (statelessSession != null) { statelessSession.close(); statelessSession = null; } if (statefulSession != null) { Method close = ReflectionUtils.findMethod(Session.class, "close"); ReflectionUtils.invokeMethod(close, statefulSession); statefulSession = null; } }
StatelessSession session = sessionFactory.openStatelessSession(); Transaction tx = session.beginTransaction(); for ( int i=0; i<100000; i++ ) { Item item = new Item(...); session.insert(item); } tx.commit(); session.close();
StatelessSession session = ((Session) entityManager.getDelegate()).getSessionFactory().openStatelessSession(); Query query = session .createQuery("SELECT a FROM Address a WHERE .... ORDER BY a.id"); query.setFetchSize(Integer.valueOf(1000)); query.setReadOnly(true); query.setLockMode("a", LockMode.NONE); ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY); while (results.next()) { Address addr = (Address) results.get(0); // Do stuff } results.close(); session.close();
@Test public void testDynamicFetch() { Session s = openSession(); s.beginTransaction(); Date now = new Date(); User me = new User( "me" ); User you = new User( "you" ); Resource yourClock = new Resource( "clock", you ); Task task = new Task( me, "clean", yourClock, now ); // :) s.save( me ); s.save( you ); s.save( yourClock ); s.save( task ); s.getTransaction().commit(); s.close(); StatelessSession ss = sessionFactory().openStatelessSession(); ss.beginTransaction(); Task taskRef = ( Task ) ss.createQuery( "from Task t join fetch t.resource join fetch t.user" ).uniqueResult(); assertTrue( taskRef != null ); assertTrue( Hibernate.isInitialized( taskRef ) ); assertTrue( Hibernate.isInitialized( taskRef.getUser() ) ); assertTrue( Hibernate.isInitialized( taskRef.getResource() ) ); assertFalse( Hibernate.isInitialized( taskRef.getResource().getOwner() ) ); ss.getTransaction().commit(); ss.close(); cleanup(); }
@Override public void close() { this.indexManager.flush(); if (s != null) { s.close(); s = null; } externalProperties = null; }
statelessSession.close();
@Test @TestForIssue( jiraKey = "HHH-11732" ) public void test() { Triggerable triggerable = logInspection.watchForLogMessages( "HHH000352" ); triggerable.reset(); StatelessSession session = entityManagerFactory().unwrap( SessionFactory.class ).openStatelessSession(); Transaction tx = session.beginTransaction(); try { Employee employee = new Employee( "1", "2", 1 ); employee.setId( 1 ); session.insert( employee ); tx.rollback(); } catch (HibernateException e) { if ( tx != null ) { tx.rollback(); } } finally { session.close(); assertFalse( triggerable.wasTriggered() ); } }
StatelessSession session = sessionFactory.openStatelessSession(); Transaction tx = session.beginTransaction(); ScrollableResults customers = session.getNamedQuery("GetCustomers") .scroll(ScrollMode.FORWARD_ONLY); while ( customers.next() ) { Customer customer = (Customer) customers.get(0); customer.updateStuff(...); session.update(customer); } tx.commit(); session.close();
@Override public void close(StatelessSession session) { if (session == null) { return; } session.close(); }
protected void closeSession() { if (currentSessionHolder.get() != null) { log.debug("close session [{}]", currentSessionHolder.get()); currentSessionHolder.get().close(); currentSessionHolder.set(null); } }
StatelessSession statelessSession = sessionFactory.openStatelessSession(); try { return statelessSession.get(Ticket.class, ticketKey, LockMode.READ) } finally { statelessSession.close() }
public void close() { this.tx.commit(); this.results.close(); this.results = null; this.session.close(); }
@Override public void close() { this.indexManager.flush(); if (s != null) { s.close(); s = null; } externalProperties = null; }
@Override public void close() { this.indexManager.flush(); if (s != null) { s.close(); s = null; } puProperties = null; }
@Override public void insert(List<ChannelSeverity> channelSeverities) { StatelessSession statelessSession = sessionFactory.openStatelessSession(); try { for (ChannelSeverity channelSeverity : channelSeverities) { statelessSession.insert(channelSeverity); } } finally { statelessSession.close(); } }
@Override public void saveOrUpdateStateless(ChannelVulnerability channelVulnerability) { StatelessSession statelessSession = sessionFactory.openStatelessSession(); statelessSession.insert(channelVulnerability); statelessSession.close(); }
if (books == null || books.isEmpty) { return; } StatelessSession session = getHibernateTemplate().getSessionFactory().openStatelessSession(); Transaction tx = session.beginTransaction(); for (Book each : books) { session.insert(book); } tx.commit(); session.close();
protected QueryCacheEntry(final String queryString, final Object... params) { StatelessSession session = factoryImplementor.openStatelessSession(); Query query = session.createQuery(queryString); for (int i = 0; i < params.length; i++) { query.setParameter(i, params[i]); } QueryImpl queryImpl = (QueryImpl)query; queryParameters = queryImpl.getQueryParameters(null); this.queryString = queryString; this.params = params; cacheRegion = factoryImplementor.getQueryCache().getRegion(); session.close(); }
// Each single thread brings resultItems from DynamoDB StatelessSession session = factory.openStatelessSession(); Transaction tx = session.beginTransaction(); for(int i = 0; i < resultItems.size(); i++) { Customer cust = new Customer(resultItems.get(i)); Long id = session.save(cust); // get the generated id // TODO: Create a list of related customer users and assign the id to all of them and then save those customer user objects in the same transaction. if(i % BATCH_SIZE == 0) { session.flush(); session.clear(); } } tx.commit(); session.close();
StatelessSession session = sessionFactory.openStatelessSession(); Transaction tx = session.beginTransaction(); ScrollableResults customers = session.getNamedQuery("GetCustomers") .scroll(ScrollMode.FORWARD_ONLY); while ( customers.next() ) { Customer customer = (Customer) customers.get(0); customer.updateStuff(...); session.update(customer); } tx.commit(); session.close();