SessionFactory openSession - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SessionFactory openSession method.

This code example shows how to use the following methods:openSession
	 * @param entityInterceptor Hibernate entity interceptor, or {@code null} if none 
	 * @return the new Session 
	 */ 
	@SuppressWarnings("deprecation") 
	public static Session getNewSession(SessionFactory sessionFactory, Interceptor entityInterceptor) { 
		Assert.notNull(sessionFactory, "No SessionFactory specified"); 
 
		try { 
			SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory); 
			if (sessionHolder != null && !sessionHolder.isEmpty()) { 
				if (entityInterceptor != null) { 
					return sessionFactory.openSession(sessionHolder.getAnySession().connection(), entityInterceptor); 
				} 
				else { 
					return sessionFactory.openSession(sessionHolder.getAnySession().connection()); 
				} 
			} 
			else { 
				if (entityInterceptor != null) { 
					return sessionFactory.openSession(entityInterceptor); 

8
CodeRank
This code example shows how to use the following methods:openSession
		} 
 
		@Override 
		public void run() { 
			try { 
				Session s = sf.openSession();
				Transaction tx = s.beginTransaction();
				Worker w = new Worker( "Mladen", 70 );
				s.persist( w );
				Construction c = new Construction( "Hover Dam", "Croatia" );
				s.persist( c );
				tx.commit();
				s.close();
 
				s = sf.openSession();
				tx = s.beginTransaction();
				w = (Worker) s.get( Worker.class, w.getId() );
				w.setName( "Remi" );
				c = (Construction) s.get( Construction.class, c.getId() );
				c.setName( "Palais des festivals" );

8
CodeRank
This code example shows how to use the following methods:openSession
 
    public static void setUpSession(SessionFactory sessionFactory, boolean clearActiveTX) {
        if (clearActiveTX) {
            if (TransactionSynchronizationManager.isSynchronizationActive()) { 
                try { 
                    TransactionSynchronizationManager.unbindResource(sessionFactory);
                } 
                catch(IllegalStateException e) {}
                TransactionSynchronizationManager.clearSynchronization(); 
            } 
        } 
         
        setUpSession(sessionFactory);
    } 
    public static void setUpSession(SessionFactory sessionFactory) {
        Session session = sessionFactory.openSession();
         
        TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
        TransactionSynchronizationManager.initSynchronization(); 
    } 

8
CodeRank
This code example shows how to use the following methods:openSession
 
		String nativeQuery = "select * from T_FOOS";
 
		hibernateQueryProvider.setSqlQuery(nativeQuery);
		hibernateQueryProvider.afterPropertiesSet();
		hibernateQueryProvider.setSession(sessionFactory.openSession());
 
		Query query = hibernateQueryProvider.createQuery();
 
		List<Foo> expectedFoos = new ArrayList<Foo>();
 
		expectedFoos.add(new Foo(1, "bar1", 1));
		expectedFoos.add(new Foo(2, "bar2", 2));
		expectedFoos.add(new Foo(3, "bar3", 3));
		expectedFoos.add(new Foo(4, "bar4", 4));
		expectedFoos.add(new Foo(5, "bar5", 5));
 
		@SuppressWarnings("unchecked") 
		List<Foo> actualFoos = query.list();
 
8
CodeRank
This code example shows how to use the following methods:openSession
        return factory.getCurrentSession();
    } 
 
    private Session listSession() {
        if (listSession == null) {
            listSession = factory.openSession();
        } 
 
        return listSession;
    } 
 
    private void begin() { 
        begin(session()); 
    } 
 
    private void begin(Session session) {
        Transaction transaction = session.beginTransaction();
        transaction.begin();
        transactions.push(transaction);
    } 
7
CodeRank
This code example shows how to use the following methods:openSession
                ApplicationContextProvider 
                    .instance() 
                    .applicationContext() 
                    .getBean(aHibernateSessionFactoryName);
 
        return new PersistenceManagerProvider(sessionFactory.openSession());
    } 
 
    public PersistenceManagerProvider(Session aHibernateSession) {
        super(); 
 
        this.setHibernateSession(aHibernateSession);
    } 
 
    public Session hibernateSession() {
        return this.hibernateSession;
    } 
 
    public boolean hasHibernateSession() { 
        return this.hibernateSession() != null;
7
CodeRank
This code example shows how to use the following methods:openSession
		this.applicationContext = applicationContext;
	} 
 
	@Override 
	public Session openSession() throws HibernateException {
		return original.openSession(new SpringInterceptor(this.applicationContext, original));
	} 
 
	@Override 
	public Session openSession(Connection connection) {
		return original.openSession(connection, new SpringInterceptor(this.applicationContext, original));
	} 
 
	@Override 
	public Session openSession(Interceptor interceptor) throws HibernateException {
        return original.openSession(interceptor);
    } 
 
    @Override 
	public Session openSession(Connection connection, Interceptor interceptor) {
7
CodeRank
This code example shows how to use the following methods:openSession
This code example shows how to use the following methods:openSession
	protected Configuration getCommonConfiguration() {
		return commonCfg;
	} 
 
	protected Session getSlaveSession() {
		return slaveSessionFactory.openSession();
	} 
 
	protected static SessionFactory getSlaveSessionFactory() {
		return slaveSessionFactory;
	} 
 
	@Override 
	protected abstract Class<?>[] getAnnotatedClasses();
 
	protected abstract Class<?>[] getCommonAnnotatedClasses();
} 
7
CodeRank
This code example shows how to use the following methods:close, openSession
public abstract class AbstractConfigurationTestCase { 
 
    protected void assertPojoCanBeSaved(SessionFactory sessionFactory, Fooable pojo) {
        Session session = null;
        try { 
            session = sessionFactory.openSession();
            Integer result = (Integer) session.save(pojo);
            assertNotNull(result);
            session.close();
 
            session = sessionFactory.openSession();
            Fooable pojo2 = (Fooable) session.load(pojo.getClass(), result);
            assertNotNull(pojo);
            assertEquals(pojo.getId(), pojo2.getId());
            assertEquals(pojo.getFoo(), pojo2.getFoo());
        } finally { 
            if (session != null && session.isOpen()) {
                session.close();
            } 
            sessionFactory.close();

6
CodeRank
openSession Method Overview
Open a Session.
See Code Examples for other Hibernate ORM SessionFactory Methods: