Configuration For Spring+Hibernate.

Setting DataSource, Hibernate Properties, Transaction Management, Spring Beans.


<bean id="dataSource" destroy-method="close" >
 <property name="driverClassName">
 <value>com.mysql.jdbc.Driver</value>
 </property>
 <property name="url">
 <value>jdbc:mysql://192.168.100.142:3306/sample</value>
 </property>
 <property name="username">
 <value>datademo</value>
 </property>
 <property name="password">
 <value>abc#123</value>
 </property>
 <property name="maxWait" value="60000"/>
 <property name="maxActive" value="100"/>
 </bean>

 <bean id="sessionFactory">
 <property name="dataSource">
 <ref bean="dataSource"/>
 </property>
 <property name="annotatedClasses">
 <list>
 <value>com.demo.model.DemoMaster</value>
</list>
 </property>
 <property name="hibernateProperties">
 <props>
 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
 <prop key="current_session_context_class">thread</prop>
 <prop key="hibernate.hbm2ddl.auto">update</prop>
 <prop key="hibernate.cache.use_second_level_cache">true</prop>
 <prop key="hibernate.connection.autocommit">true</prop>
 <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
 <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
 <prop key="hibernate.max_fetch_depth">5</prop>
 <prop key="hibernate.default_batch_fetch_size">16</prop>
 <prop key="hibernate.jdbc.batch_size">25</prop>
 <prop key="hibernate.jdbc.fetch_size">8</prop>
 </props>
 </property>
 </bean>
 <bean id="transactionManager" p:sessionFactory-ref="sessionFactory" />

 <beanĀ  id="hibernateTemplate">
 <property name="sessionFactory">
 <ref bean="sessionFactory"/>
 </property>
 </bean>

 <bean id="hibernateInterceptor">
 <property name="sessionFactory" ref="sessionFactory" />
 </bean>

 <!--DAO BEANS-->
 <bean id="DemoMasterDao">
 <property name="sessionFactory" ref="sessionFactory" />
 </bean>

Advertisements
This entry was posted in Spring. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s