Hiberante spring integration

All you need to do is to config the following 2 beans in your spring config file.

 

 

<!-- Hibernate configuration -->

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"

destroy-method="close">

          <property name="driverClass" value="com.sybase.jdbc2.jdbc.SybDataSource"/>

          <property name="jdbcUrl" value="jdbc:sybase:Tds:hkeqrmsu1.ap.ssmb.com:4100/DRMS"/>

          <property name="user" value="eqjobs"/>

          <property name="password" value="jobs99"/>

          <property name="minPoolSize" value="2"/>

          <property name="acquireIncrement" value="1"/>

          <property name="maxPoolSize" value="20"/>

          <property name="idleConnectionTestPeriod" value="3000"/>

          <property name="maxStatements" value="100"/>

</bean>

     

<bean id="hibernateSessionFactory"

      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

 <property name="dataSource" ref="dataSource"/>

 <property name="mappingLocations" value="classpath*:hibernate/mappingResources/*.hbm.xml"/>

 <property name="hibernateProperties">

    <props>

       <prop key="hibernate.dialect">org.hibernate.dialect.SybaseDialect</prop>

<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>

    </props>

 </property>

</bean>

 

Something to Explain

1) Basically, Hibernate is an O/R mapping tool. So, the most important bean should be a datasource. Alternatively, you can config your bean in another way, using JNDI.

 

      <bean id="dataSource1"  class="org.springframework.jndi.JndiObjectFactoryBean">    

            <property name="jndiName">

                  <value>java:comp/env/jdbc/trainingDatasource</value>

            </property>

      </bean>

 

2) If you use Hibernate alone, definitely, you need to supply a Hibernate config file – hibernate.properties which looks like this:

 

hibernate.query.substitutions yes 'Y', no 'N'

hibernate.connection.pool_size 1

hibernate.proxool.pool_alias pool1

hibernate.show_sql true

hibernate.format_sql true

hibernate.max_fetch_depth 1

hibernate.jdbc.batch_versioned_data true

hibernate.jdbc.use_streams_for_binary true

hibernate.cache.region_prefix hibernate.test

hibernate.cache.use_second_level_cache true

hibernate.cache.use_query_cache true

hibernate.cache.provider_class org.hibernate.cache.EhCacheProvider

 

When integrated with Spring together, there is no need to supply this config file. You can just put everything into the hibernateProperties property in hibernateSessionFactory

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值