这几天在搭建一个新架构,引用了spring 2.5.6中新加的特性,就是自动扫描Class的hibernate映射文件。
我的class都在com.pplus.model这个包里,注意下面红色的配置

<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">
            <value>
                hibernate.dialect=${hibernate.dialect}
                hibernate.query.substitutions=true 'Y', false 'N'
                hibernate.cache.use_second_level_cache=true
                hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
            </value>
            <!-- Turn batching off for better error messages under PostgreSQL -->
            <!-- hibernate.jdbc.batch_size=0 -->
        </property>
        <property name="packagesToScan">
            <list>
              <value>com.pplus.*</value>  <!--若写成com.pplus.model.* 则映射不到,还没有来得及看源代码 -->
            </list>
         </property>
    </bean>