欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring Hibernate SessionFactory packagesToScan Bug

程序员文章站 2022-04-14 09:15:13
...
2009年4月20日


<!-- 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">
org.hibernate.dialect.MySQL5Dialect
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.format_sql">
${hibernate.format_sql}
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop
key="hibernate.cache.provider_configuration_file_resource_path">
${hibernate.ehcache_config_file}
</prop>
</props>
</property>

<!-- 使用packagesToScan属性已批量定义了sessionFactory加载的实体对象 -->
<property name="packagesToScan" value="com.store.entity.*" />

<!--
<property name="annotatedClasses">
<list>
<value>com.store.entity.Item</value>
</list>
</property>
-->
</bean>


[b]上面的packagesToScan扫描的范围为 com.store.entity下的包,不能把Entity直接放在com.store.entity下面,Spring不扫描此包。[/b]