Spring集成hibernate

方式一:使用hibernate.cfg.xml配置sessionFactory
hibernate.cfg.xml配置实例
<hibernate-configuration>
<session-factory>
  <property name="show_sql">true</property>
  <property name="dialect">org.hibernate.dialect.Oracle9iDialect</property>
  <property name="hibernate.max_fetch_depth">0</property>
  <property name="hibernate.jdbc.fetch_size">50</property>
  <property name="hibernate.jdbc.batch_size">10</property>
  <property name="hibernate.jndi.weblogic.jndi.replicateBindings">false</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<mapping resource="com/xx/aa.hbm.xml"/>
</session-factory>
</hibernate-configuration>

spring中配置对应的事物以及数据源和sessionFactory
<import resource="x/a.xml"/>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<!--value>java:comp/env/aaa</value-->
<value>bbb</value>
</property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>

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

//spring中的sessionFactory节点才是真正的spring所需要的节点,它可以关联hibernate的sessionFactory和spring中定义的数据源
spring中定义的sessionFactory节点最终是要注入给spring中的事物的

你可能感兴趣的:(Spring集成hibernate)