Hibernate ORM SessionFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM SessionFactory class.

This code example shows how to use the following methods: getCurrentSession
		this.sessionFactory = sessionFactory;
	} 
 
	@Override 
	public Person save(Person person) {
		this.sessionFactory.getCurrentSession().save(person);
		return person;
	} 
 
	@Override 
	public Person findByName(String name) {
		return (Person) this.sessionFactory.getCurrentSession().createQuery(
			"from Person person where person.name = :name").setString("name", name).uniqueResult();
	} 
} 
Full Snippet Info
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getCurrentSession
	@Autowired 
	private SessionFactory sessionFactory;
 
	public void save(final PersistentScriptTemplate t)
	{ 
		sessionFactory.getCurrentSession().saveOrUpdate(t);
	} 
 
	@SuppressWarnings("unchecked") 
	public List<PersistentScriptTemplate> findAll(final Lang lang)
	{ 
		return sessionFactory.getCurrentSession()
			.createCriteria(PersistentScriptTemplate.class)
			.add(Restrictions.eq("lang", lang))
			.list(); 
	} 
 
	public PersistentScriptTemplate get(final Long id)
	{ 
		return (PersistentScriptTemplate)sessionFactory.getCurrentSession().get(
Full Snippet Info
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getCurrentSession
	 *  
	 * @return hibernate session 
	 */ 
	protected Session getSession()
	{ 
		return factory.getCurrentSession();
	} 
 
	/** 
	 * Load a {@link Contact} from the DB, given it's <tt>id</tt> . 
	 *  
	 * @param id 
	 *            The id of the Contact to load. 
	 * @return Contact 
	 */ 
	public Contact load(long id)
	{ 
		return (Contact)getSession().get(Contact.class, Long.valueOf(id));
	} 
 
Full Snippet Info
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getCurrentSession
 
	} 
 
	@Test
	public void testWriteAndFlushSunnyDayHibernate4() throws Exception {
		writer.setSessionFactory(factory);
		when(factory.getCurrentSession()).thenReturn(currentSession);
		when(currentSession.contains("foo")).thenReturn(true);
		when(currentSession.contains("bar")).thenReturn(false);
		currentSession.saveOrUpdate("bar");
		currentSession.flush();
		currentSession.clear();
 
		List<String> items = Arrays.asList(new String[] { "foo", "bar" });
		writer.write(items);
	} 
 
	@Test
	public void testWriteAndFlushWithFailureHibernate4() throws Exception {
		writer.setSessionFactory(factory);
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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();
 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getCurrentSession
     * 
     * @throws org.springframework.beans.BeansException 
     *          when can't find 'sessionFactory' bean 
     */ 
    protected void flush() throws BeansException {
        Session currentSession = sessionFactory.getCurrentSession();
        currentSession.flush();
    } 
 
    /** 
     * Flush search indexes, to be done after a reindex() or reindexAll() operation 
     */ 
    public void flushSearchIndexes() { 
        Session currentSession = sessionFactory.getCurrentSession();
        final FullTextSession fullTextSession = Search.getFullTextSession(currentSession);
        fullTextSession.flushToIndexes();
    } 
} 
Full Snippet Info
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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);
    } 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Hibernate ORM SessionFactory Methods: