Spring Framework HibernateTemplate - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework HibernateTemplate class.

This code example shows how to use the following methods:afterPropertiesSet, getObject, setDataSource, setMappingLocations
This code example shows how to use the following methods:getSessionFactory, isAllowCreate, getEntityInterceptor, getJdbcExceptionTranslator
 
	/** 
	 * Return the Hibernate SessionFactory used by this DAO. 
	 */ 
	public final SessionFactory getSessionFactory() { 
		return (this.hibernateTemplate != null ? this.hibernateTemplate.getSessionFactory() : null); 
	} 
 
	/** 
	 * Set the HibernateTemplate for this DAO explicitly, 
	 * as an alternative to specifying a SessionFactory. 
	 * @see #setSessionFactory 
	 */ 
	public final void setHibernateTemplate(HibernateTemplate hibernateTemplate) { 
		this.hibernateTemplate = hibernateTemplate; 
	} 
 
	/** 
	 * Return the HibernateTemplate for this DAO, 
	 * pre-initialized with the SessionFactory or set explicitly. 

7
CodeRank
This code example shows how to use the following methods:
	 * @param sessionFactory the Hibernate SessionFactory to create a HibernateTemplate for 
	 * @return the new HibernateTemplate instance 
	 * @see #setSessionFactory 
	 */ 
	protected HibernateTemplate createHibernateTemplate(SessionFactory sessionFactory) {
		return new HibernateTemplate(sessionFactory);
	} 
 
	/** 
	 * Return the Hibernate SessionFactory used by this DAO. 
	 */ 
	public final SessionFactory getSessionFactory() {
		return (this.hibernateTemplate != null ? this.hibernateTemplate.getSessionFactory() : null);
	} 
 
	/** 
	 * Set the HibernateTemplate for this DAO explicitly, 
	 * as an alternative to specifying a SessionFactory. 
	 * @see #setSessionFactory 
	 */ 
5
CodeRank
This code example shows how to use the following methods:find, flush, save
 
    public void insertByLevel(int level) { 
        Person p = new Person(); 
        p.setName("akweiwei"); 
        p.setLevel(level); 
        this.hibernateTemplate.save(p); 
        @SuppressWarnings("unchecked") 
        List<Person> list = this.hibernateTemplate.find( 
                "from Person where level=?", level); 
        this.hibernateTemplate.find( 
                "from Person p0,Person p1 where p0.level=? and p0.pid=p1.pid", 
                level); 
        Assert.assertEquals(1, list.size()); 
        Person dbp = list.get(0); 
        Assert.assertEquals(p.getPid(), dbp.getPid()); 
        Assert.assertEquals(p.getName(), dbp.getName()); 
        Assert.assertEquals(p.getLevel(), dbp.getLevel()); 
        dbp.setName("newakwei"); 
        hibernateTemplate.save(dbp); 
        hibernateTemplate.flush(); 

6
CodeRank
This code example shows how to use the following methods:afterPropertiesSet, getObject, setDataSource, setHibernateProperties, setPackagesToScan
  } 
 
  @Bean 
  public SessionFactory sessionFactoryBean() { 
    try { 
      LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean(); 
      lsfb.setDataSource(dataSource()); 
      lsfb.setPackagesToScan("spittr.domain"); 
      Properties props = new Properties(); 
      props.setProperty("dialect", "org.hibernate.dialect.H2Dialect"); 
      lsfb.setHibernateProperties(props); 
      lsfb.afterPropertiesSet(); 
      SessionFactory object = lsfb.getObject(); 
      return object; 
    } catch (IOException e) { 
      return null; 
    } 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:setDataSource, setHibernateProperties, setPackagesToScan
    @Autowired 
    private PropertiesStrategyManager hibPropStrategyManager; 
 
    @Bean 
    public LocalSessionFactoryBean gpSessionFactoryBean() { 
        final LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean(); 
        factoryBean.setDataSource(this.persitenceDataSource); 
        factoryBean.setPackagesToScan( 
                this.gpPersistenceConnector.getPackagesToScan()); 
        factoryBean.setHibernateProperties( 
                this.hibPropStrategyManager.getProperties()); 
 
        return factoryBean; 
    } 
 
    @Bean 
    public HibernateTransactionManager transactionManager() { 
        final HibernateTransactionManager txManager = new HibernateTransactionManager(); 
        txManager.setSessionFactory(this.gpSessionFactoryBean().getObject()); 
 
6
CodeRank
This code example shows how to use the following methods:
			request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST); 
		} 
		else { 
			logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor"); 
			Session session = openSession(); 
			SessionHolder sessionHolder = new SessionHolder(session); 
			TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder); 
 
			AsyncRequestInterceptor asyncRequestInterceptor = 
					new AsyncRequestInterceptor(getSessionFactory(), sessionHolder); 
			asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor); 
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor); 
		} 
	} 
 
	@Override 
	public void postHandle(WebRequest request, ModelMap model) { 
	} 
 
	/** 
6
CodeRank
This code example shows how to use the following methods:
public class HibernateUserDAO implements UserDAO { 
 
	private HibernateTemplate hibernateTemplate; 
 
	public void setSessionFactory(SessionFactory sessionFactory) { 
		this.hibernateTemplate = new HibernateTemplate(sessionFactory); 
	} 
 
	public void save(User user) { 
		hibernateTemplate.saveOrUpdate(user); 
	} 
 
	public List<User> findAll() { 
		return hibernateTemplate.find("from User"); 
	} 
 
    public void remove(User user) { 
        hibernateTemplate.delete(user); 
    } 
 
6
CodeRank
This code example shows how to use the following methods:
	@Override 
	protected void setUpResources(DataSource dataSource) throws Exception { 
		sessionFactory = getSessionFactory(dataSource); 
		hibernateTemplate = new HibernateTemplate(sessionFactory); 
		hibernateTemplate.setCheckWriteOperations(false); 
		HibernateTransactionManager tm = new HibernateTransactionManager(sessionFactory); 
		executionListener = new HibernateFlowExecutionListener(sessionFactory, tm); 
		rowCount = 1; 
	} 
 
	@Override 
	protected FlowExecutionListener getListener() { 
		return executionListener; 
	} 
 
	@Override 
	protected void assertSessionNotBound() { 
		assertNull(TransactionSynchronizationManager.getResource(sessionFactory)); 
	} 
 
6
CodeRank
This code example shows how to use the following methods:setAllowCreate
   * Creates an instance. 
   *  
   * @param hibernateTemplate  the hibernateTemplate, not null 
   */ 
  public HibernateTemplateProvider(HibernateTemplate hibernateTemplate) {
    ArgumentChecker.notNull(hibernateTemplate, "hibernateTemplate");
    _hibernateTemplate = hibernateTemplate;
    _hibernateTemplate.setAllowCreate(false);
  } 
 
  //------------------------------------------------------------------------- 
   
  /** 
   * Gets the local Hibernate template. 
   * 
   * @return the template, not null 
   */ 
  public HibernateTemplate getHibernateTemplate() {
    return _hibernateTemplate;
  } 
6
CodeRank
See Code Examples for Spring Framework HibernateTemplate Methods: