我们使用spring整合hibernate的时候,通用需要指定默认扫描的类,在指定的地方可以用*匹配多个字符,非常实用。当然也可以逐个指定。
<!-- Hibernate配置 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache/ehcache-hibernate-local.xml</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.companyname.*.entity</value>
</list>
</property>
</bean>

本文介绍如何在Spring框架中整合Hibernate,实现ORM操作。通过配置AnnotationSessionFactoryBean,设置数据源、命名策略、Hibernate属性及扫描包路径等参数。
349

被折叠的 条评论
为什么被折叠?



