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: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: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: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
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:setSessionFactory
 
@Repository("organizationDao") 
public class OrganizationDaoImpl extends HibernateDaoSupport implements OrganizationDao { 
 
  @Autowired 
  public OrganizationDaoImpl(SessionFactory sessionFactory) { 
    setSessionFactory(sessionFactory); 
  } 
 
  public Organization load(Long id) { 
    return (Organization) getHibernateTemplate().load(Organization.class, id); 
  } 
 
  public Organization persist(Organization organization) { 
    getHibernateTemplate().saveOrUpdate(organization); 
    return organization; 
  } 
 
  @SuppressWarnings("unchecked") 
  public Organization findByName(String orgName) { 
7
CodeRank
This code example shows how to use the following methods:setPackagesToScan, afterPropertiesSet, getObject, setDataSource, setHibernateProperties
public class AppConfigWithoutComponentScan 
{ 
    @Bean 
    public SessionFactory sessionFactory() throws ExceptionAnnotationSessionFactoryBean bean = new AnnotationSessionFactoryBean();
        bean.setDataSource(dataSource());
        bean.setPackagesToScan(new String[] {"org.springframework.issues"});
        bean.setHibernateProperties(hibernateProps());
        bean.afterPropertiesSet();
        return bean.getObject();
    } 
 
    private Properties hibernateProps()
    { 
        Properties jpaProperties = new Properties();
        jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
        jpaProperties.put("hibernate.hbm2ddl.auto", "create-drop");
        jpaProperties.put("hibernate.show_sql", false);
        jpaProperties.put("hibernate.format_sql", true);
7
CodeRank
This code example shows how to use the following methods:addSession, doesNotHoldNonDefaultSession, getValidatedSession, isEmpty, setPreviousFlushMode

7
CodeRank
This code example shows how to use the following methods:setSessionFactory
 
@Repository("userDao") 
public class UserDaoImpl extends HibernateDaoSupport implements UserDao { 
 
  @Autowired 
  public UserDaoImpl(SessionFactory sessionFactory) { 
    setSessionFactory(sessionFactory); 
  } 
 
  public User load(Long id) { 
    return (User) getHibernateTemplate().load(User.class, id); 
  } 
 
  public User persist(User user) { 
    getHibernateTemplate().saveOrUpdate(user); 
    return user; 
  } 
 
  @SuppressWarnings("unchecked") 
  public User findUserByOrganizationAndUsername(Long organizationId, String username) { 
7
CodeRank
This code example shows how to use the following methods:setDefaultFilterCondition, setFilterName, setParameterTypes, getDefaultCondition, getParameterTypes
     */ 
    public AbstractSecurityFilter() { 
        this(new Roles()); 
    } 
 
    public AbstractSecurityFilter(Roles roles) {
        this.roles = roles;
        this.setFilterName(getName());
        this.setParameterTypes(getParameterTypes());
        this.setDefaultFilterCondition(getDefaultCondition());
    } 
 
    public String getName() {
        return this.getClass().getSimpleName();
    } 
 
    public void disable(Session sess) {
	    sess.disableFilter(getName());
	    disableBaseFilters(sess);
    } 
7
CodeRank
This code example shows how to use the following methods:addSession, doesNotHoldNonDefaultSession, getValidatedSession, isEmpty, setPreviousFlushMode

7
CodeRank
See Code Examples for Spring Framework HibernateTemplate Methods: