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();
 }
예제 #2
0
파일: DbConfig.java 프로젝트: casoc/curd
 @Bean
 public SessionFactory sessionFactory() throws Exception {
   // Hibernate 3 use this class but 4 use LocalSessionFactoryBean
   AnnotationSessionFactoryBean sessionFactory = new AnnotationSessionFactoryBean();
   sessionFactory.setDataSource(dataSource());
   Properties properties = new Properties();
   properties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
   properties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
   properties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
   properties.setProperty("hibernate.format_sql", env.getProperty("hibernate.format_sql"));
   sessionFactory.setHibernateProperties(properties);
   sessionFactory.setPackagesToScan(new String[] {"com.demo.curd.entity"});
   sessionFactory
       .afterPropertiesSet(); // if don't call this method you will can't get right SessionFactory
                              // object
   return sessionFactory.getObject();
 }