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

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
Contextual code suggestions in your IDE  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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setAnnotatedClasses, afterPropertiesSet, getObject, setDataSource, setHibernateProperties
		transactionManager.rollback(transactionStatus);
	} 
 
	private SessionFactory createTestSessionFactory() throws Exception {
		// create a FactoryBean to help create a Hibernate SessionFactory 
		AnnotationSessionFactoryBean factoryBean = new AnnotationSessionFactoryBean();
		factoryBean.setDataSource(createTestDataSource());
		factoryBean.setAnnotatedClasses(new Class [] {Restaurant.class});
		factoryBean.setHibernateProperties(createHibernateProperties());
		// initialize according to the Spring InitializingBean contract 
		factoryBean.afterPropertiesSet();
		// get the created session factory 
		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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setAnnotatedClasses, afterPropertiesSet, getObject, setDataSource, setHibernateProperties
		transactionManager.rollback(transactionStatus);
	} 
 
	private SessionFactory createTestSessionFactory() throws Exception {
		// create a FactoryBean to help create a Hibernate SessionFactory 
		AnnotationSessionFactoryBean factoryBean = new AnnotationSessionFactoryBean();
		factoryBean.setDataSource(createTestDataSource());
		factoryBean.setAnnotatedClasses(new Class [] {Account.class, Beneficiary.class});
		factoryBean.setHibernateProperties(createHibernateProperties());
		// initialize according to the Spring InitializingBean contract 
		factoryBean.afterPropertiesSet();
		// get the created session factory 
		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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setAnnotatedClasses, setDataSource, setHibernateProperties, setSchemaUpdate
		 
		Properties props = new Properties();
		props.put("hibernate.dialect", H2Dialect.class.getName());
		props.put("hibernate.format_sql", "true");
 
		AnnotationSessionFactoryBean bean = new AnnotationSessionFactoryBean();
		 
		bean.setAnnotatedClasses(
				new Class[]{
						Item.class,  
						Order.class 
				} 
		); 
		 
		bean.setHibernateProperties(props);
		 
		bean.setDataSource(this.dataSource);
		 
		bean.setSchemaUpdate(true);
 

6
CodeRank
Contextual code suggestions in your IDE  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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setPackagesToScan, setDataSource, setHibernateProperties
      return new DriverManagerDataSource(String.format("jdbc:postgresql:%s", converterDbName), dbUsername, dbPassword); 
   } 
 
   @Bean 
   public AnnotationSessionFactoryBean converterSessionFactoryBean() { 
      AnnotationSessionFactoryBean factory = new AnnotationSessionFactoryBean(); 
      factory.setPackagesToScan(new String[]{"com.vmware.thinapp.manualmode"}); 
      factory.setDataSource(converterDataSource()); 
      Properties hibProps = new Properties(); 
      hibProps.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); 
      // Don't automatically update database schema but validate that it's correct. 
      hibProps.setProperty("hibernate.hbm2ddl.auto", "validate"); 
      factory.setHibernateProperties(hibProps); 
      return factory; 
   } 
 
   @Bean 
   public SessionFactory converterSessionFactory() { 
      return converterSessionFactoryBean().getObject(); 
   } 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addSession, doesNotHoldNonDefaultSession, getValidatedSession, isEmpty, setPreviousFlushMode

7
CodeRank
Contextual code suggestions in your IDE  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
Contextual code suggestions in your IDE  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
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Spring Framework AnnotationSessionFactoryBean Methods: