- 声明Hibernate的Session工厂Bean
- setDatabaSource设置数据源
-
setMappingResources设置Hibernate映射文件(.hbm.xml)
setPackagesToScan设置自动扫描的位置
- setHibernateProperties设置属性-方言(dialet)
- 实体类加@Entity
- 借助Hibernate Session实现不依赖于Spring的Repository//不使用Template而是使用上下文Session(contextual session)
- @Repository注解类,被自动扫描,使用Spring统一非检查型异常的形式抛出
- 注入SessionFactory
- 从SessionFactory中获取CurrentSession
- 使用currentsession
- 为了不使用模板Hibernate Repository需在Spring上下文中添加PersistenceExceptionTranslationPostProcessor Bean一个bean 后置处理器(bean post-processor,它会在所有拥有@Repository注解的类上添加一个通知器(advisor),这样就会捕获任何平台相关的异常并以Spring非检查型数据访问异常的形式重新抛出