如何将Hibernate类映射转换为Spring应用程序上下文?

如何在Spring 应用程序上下文中配置类org.springframework.orm.hibernate3.LocalSessionFactoryBean的Hibernate类映射? 我想将会话工厂类映射从以下hibernate.cfg.xml到相应的Spring会话工厂bean,以便我可以消除hibernate.cfg.xml

文件hibernate.cfg.xml

               

文件spring-application-context.xml

   org.hibernate.cfg.AnnotationConfiguration   classpath:hibernate.cfg.xml   <--    Queries.hbm.xml     org.hibernate.dialect.Oracle10gDialect   -->  

如果您正在使用JPA注释类,则可以使用AnnotationSessionFactoryBean而不是LocalSessionFactoryBean ,并将类直接注入Spring bean:

     com.company.app.common.model.Account com.company.app.common.model.AccountCategory com.company.app.common.model.AssetType com.company.app.common.model.Book com.company.app.model.AssetTypeCategory     Queries.hbm.xml     org.hibernate.dialect.Oracle10gDialect    

作为skaffman 答案的一个细微变化,我使用AnnotationSessionFactoryBean类的属性packagesToScan来避免列出所有单独的模型类名:

     com.company.app.common.model     Queries.hbm.xml     org.hibernate.dialect.Oracle10gDialect    

我从优秀的Spring in Action,第三版中了解到了这个属性。

我也面临同样的问题,这对我有用 –

        com.odeon.audit.dao.entity.AuditLogEntity com.odeon.audit.dao.entity.AuditLogApplicationEtity com.odeon.audit.dao.entity.AuditLogModuleEntity com.odeon.audit.dao.entity.AuditLogOperationEntity     #{auditCoreProp.getString('jdbc.dialect')} #{auditCoreProp.getString('jdbc.show_sql')} #{auditCoreProp.getString('jdbc.hbm2ddl.auto')}