hibernate4不使用hibernate3的AnnotationSessionFactoryBean配置sessionFactory

hibernate4在sessionFactory的配置中,和hibernate3有些区别,hibernate4使用org.springframework.orm.hibernate4.LocalSessionFactoryBean配置sessionFactory. 而hibernate3使用org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean类配置sessionFactory,请看以下hibernate4的sessionFactory配置 代码:

 

<!-- Hibernate4配置 -->
<bean id="sessionFactory"
  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com" />
    <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>
        </props>
    </property>
</bean>

 hibernate3的sessionFactory使用配置,用annotatedClasses属性显示指定实体类,配置代码如下:

 

 

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
   <property name="dataSource" ref="dataSource"/>
   <property name="annotatedClasses">
     <list>
       <value>com.example.Foo</value>
       <value>com.example.Bar</value>
     </list>
   </property>
 </bean>

 hibernate3的sessionFactory使用配置,用packagesToScan属性让spring自动查找实体类,配置代码如下

 

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
   <property name="dataSource" ref="dataSource"/> 
   <property name="packagesToScan" value="test.package"/>
 </bean>

 

你可能感兴趣的:(hibernate4不使用hibernate3的AnnotationSessionFactoryBean配置sessionFactory)