Spring 2.5+hibernate 3.0統合


hibernate 3.0プロファイルとspring 2.5.6プロファイルはsrcディレクトリの下に置かれています.
Springプロファイルは次のように構成されています.


   <tx:annotation-driven transaction-manager="txManager"/>

  <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
  </bean>


	<bean id="hbmlist" class="java.util.ArrayList">
	    <constructor-arg>
	        <list>
		         <value>/conf/model/User.hbm.xml</value>
                <value>/conf/model/DictItem.hbm.xml</value>
	        </list>
	    </constructor-arg>
	</bean>

	<bean id="hibernateProperties"
	        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
	        <property name="properties">
	            <props>
	                <prop key="hibernate.dialect">${mysql.hibernate.dialect}</prop>       
	                 <prop key="hibernate.show_sql">true</prop>
	                 <prop key="hibernate.format_sql">true</prop>
	                <!--   
	                  <prop key="hibernate.cache.use_second_level_cache">true</prop>
                      <prop key="hibernate.cache.use_query_cache">true</prop>
                      <prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
	                -->
	                 <!--
	                 <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>                
	                 <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>    
	                 <prop key="hibernate.query.substitutions" >true</prop>
	                 <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
	                 -->
	                <!-- <prop key="hibernate.hbm2ddl.auto">update</prop>  -->
	                <!--  <prop key="hibernate.cache.use_query_cache">true</prop>-->
	                <!--  <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>-->
	            </props>
	        </property>
	</bean>


	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
	  <property name="locations">
	   <list>
	    <value>classpath:/conf/dbusers.properties</value>
	   </list>
	  </property>
	 </bean>

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" >
         <value>${mysql.driverName}</value>
        </property>
        <property name="url">
            <value>${mysql.url}</value>
        </property>
        <property name="username">
            <value>${mysql.user}</value>
        </property>
        <property name="password">
            <value>${mysql.password}</value>
        </property>
    </bean>


  
 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="mappingResources" ref="hbmlist"/>
    <property name="hibernateProperties" ref="hibernateProperties"/>
  </bean>

2、すべてのdaoクラスがorgを継承する.springframework.orm.hibernate3.support.HibernateDaoSupport