Spring Framework LocalSessionFactoryBean - 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 LocalSessionFactoryBean class.

This code example shows how to use the following methods:setMappingLocations, afterPropertiesSet, getObject, setDataSource
				.getBenefitAvailabilityPolicy()); 
	} 
 
	private SessionFactory createTestSessionFactory() throws Exception {
		// simulate the Spring bean initialization lifecycle 
		LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
		factoryBean.setDataSource(createTestDataSource());
		Resource[] mappingLocations = new ClassPathResource[] { new ClassPathResource("Restaurant.hbm.xml",
				Restaurant.class) }; 
		factoryBean.setMappingLocations(mappingLocations);
		factoryBean.afterPropertiesSet();
		return (SessionFactory) factoryBean.getObject();
	} 
 
	private DataSource createTestDataSource() {
		Resource schemaLocation = new ClassPathResource("/rewards/testdb/schema.sql");
		Resource testDataLocation = new ClassPathResource("/rewards/testdb/test-data.sql");
		return new TestDataSourceFactory("rewards", schemaLocation, testDataLocation).getDataSource();
	} 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:afterPropertiesSet, getObject, setDataSource, setMappingLocations
	private DataSource dataSource;
 
	private void initializeItemReader(HibernateCursorItemReader<?> reader,
			String hsqlQuery) throws Exception {
 
		LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
		factoryBean.setDataSource(dataSource);
		factoryBean.setMappingLocations(new Resource[] { new ClassPathResource(
				"Foo.hbm.xml", getClass()) });
		factoryBean.afterPropertiesSet();
 
		SessionFactory sessionFactory = factoryBean
				.getObject();
 
		reader.setQueryString(hsqlQuery);
		reader.setSessionFactory(sessionFactory);
		reader.afterPropertiesSet();
		reader.setSaveState(true);
		reader.open(new ExecutionContext());
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPackagesToScan, afterPropertiesSet, getObject, setDataSource, setHibernateProperties
public class AppConfigWithComponentScan 
{ 
    @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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addSession, doesNotHoldNonDefaultSession, getValidatedSession, isEmpty, setPreviousFlushMode

7
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:addSession, doesNotHoldNonDefaultSession, getValidatedSession, isEmpty, setPreviousFlushMode

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 *  
 */ 
@SuppressWarnings("unchecked") 
public class ContactDaoImpl extends HibernateDaoSupport implements ContactDao { 
 
	public ContactDaoImpl() { 
		// TODO Auto-generated constructor stub 
	} 
 
	public void addUpdateContact(Contact contact) { 
		getHibernateTemplate().merge(contact); 
	} 
 
	public void deleteContact(Contact contact) { 
		getHibernateTemplate().delete(contact); 
	} 
 
	public Collection<Contact> findAllContacts() { 
		return getHibernateTemplate().find("from Contact c"); 
		// return getHibernateTemplate().loadAll(Contact.class); 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework LocalSessionFactoryBean Methods: