Hibernate ORM Session - 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 Session class.

This code example shows how to use the following methods: flush
 
	@Override 
	public void flush() { 
		try { 
			SessionFactoryUtils.logger.debug("Flushing Hibernate Session on explicit request"); 
			this.session.flush();
		} 
		catch (HibernateException ex) {
			throw SessionFactoryUtils.convertHibernateAccessException(ex);
		} 
	} 
 
 
	@Override 
	public boolean equals(Object obj) { 
		return (obj instanceof SpringFlushSynchronization &&
				this.session == ((SpringFlushSynchronization) obj).session);
	} 
 
	@Override 
Full Snippet Info
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: close
	 * @see org.hibernate.Session#close() 
	 */ 
	public static void closeSession(Session session) {
		if (session != null) {
			try { 
				session.close();
			} 
			catch (HibernateException ex) {
				logger.debug("Could not close Hibernate Session", ex);
			} 
			catch (Throwable ex) {
				logger.debug("Unexpected exception on closing Hibernate Session", ex);
			} 
		} 
	} 
 
	/** 
	 * Convert the given HibernateException to an appropriate exception 
	 * from the {@code org.springframework.dao} hierarchy. 
	 * @param ex HibernateException that occurred 
Full Snippet Info
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: persist
        log.info("Registering " + member.getName());
        // em.persist(member); 
 
        // using Hibernate session(Native API) and JPA entitymanager 
        Session session = (Session) em.getDelegate();
        session.persist(member);
        memberEventSrc.fire(member);
    } 
} 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: delete
		return entity;
	} 
	 
	public void delete(T entity) {
		Session session = PersistContext.getSession(isCloudStackSession);
		session.delete(entity);
	} 
	 
	public T queryEntity(String hql, Object[] params) {
		Session session = PersistContext.getSession(isCloudStackSession);
		Query query = session.createQuery(hql);
		query.setMaxResults(1);
		QueryHelper.bindParameters(query, params);
		return (T)query.uniqueResult();
	} 
	 
	public List<T> queryEntities(String hql, Object[] params) {
		Session session = PersistContext.getSession(isCloudStackSession);
		Query query = session.createQuery(hql);
		QueryHelper.bindParameters(query, params);
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: flush
	 * @throws HibernateException in case of Hibernate flushing errors 
	 */ 
	protected void flushIfNecessary(Session session, boolean existingTransaction) throws HibernateException { 
		if (getFlushMode() == FLUSH_EAGER || (!existingTransaction && getFlushMode() != FLUSH_NEVER)) { 
			logger.debug("Eagerly flushing Hibernate session"); 
			session.flush(); 
		} 
	} 
 
 
	/** 
	 * Convert the given HibernateException to an appropriate exception 
	 * from the {@code org.springframework.dao} hierarchy. 
	 * <p>Will automatically apply a specified SQLExceptionTranslator to a 
	 * Hibernate JDBCException, else rely on Hibernate's default translation. 
	 * @param ex HibernateException that occured 
	 * @return a corresponding DataAccessException 
	 * @see SessionFactoryUtils#convertHibernateAccessException 
	 * @see #setJdbcExceptionTranslator 
	 */ 
Full Snippet Info
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: beginTransaction
	} 
 
	@Override 
	protected void open() { 
		session = sessionFactory.openSession();
		tx = session.beginTransaction();
	} 
	@SuppressWarnings("unchecked") 
	@Override 
	protected <T> T find(Class<T> entityClass, Serializable id) {
		return (T)session.load(entityClass, id);
	} 
	@Override 
	protected <T> T save(T entity) {
		session.save(entity);
		return entity;
	} 
	@SuppressWarnings("unchecked") 
	@Override 
	protected <T> T merge(T entity) {
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: clear, contains, flush, saveOrUpdate
	} 
 
	@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);
		final RuntimeException ex = new RuntimeException("ERROR");
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: close
	 */ 
	public static void closeSession(Session session) { 
		if (session != null) { 
			logger.debug("Closing Hibernate Session"); 
			try { 
				session.close(); 
			} 
			catch (HibernateException ex) { 
				logger.debug("Could not close Hibernate Session", ex); 
			} 
			catch (Throwable ex) { 
				logger.debug("Unexpected exception on closing Hibernate Session", ex); 
			} 
		} 
	} 
 
} 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: beginTransaction
	} 
	 
	@Override 
	protected void open() { 
		session = sessionFactory.openSession();
		tx = session.beginTransaction();
	} 
	@SuppressWarnings("unchecked") 
	@Override 
	protected <T> T find(Class<T> entityClass, Serializable id) {
		return (T)session.load(entityClass, id);
	} 
	@Override 
	protected <T> T save(T entity) {
		session.save(entity);
		return entity;
	} 
	@SuppressWarnings("unchecked") 
	@Override 
	protected <T> T merge(T entity) {
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: clear, flush
    } 
 
    private void commitBatch(int numProcessed) throws SecurityException,
            IllegalStateException, RollbackException, HeuristicMixedException,
            HeuristicRollbackException, SystemException, NotSupportedException {
        session.flush();
        session.clear();
        Transaction.instance().commit();
        Transaction.instance().begin();
    } 
 
} 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Hibernate ORM Session Methods: