Hibernate Configuration Properties

Hibenate configuration parameters

Here is a general hibernate session configuration file:

 

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
    <property name="hibernate.use_outer_join">true</property>
    <property name="hibernate.show_sql">false</property>

    <!-- cache properties -->
    <property name="hibernate.cache.use_query_cache">false</property>
    <property name="hibernate.generate_statistics">false</property>
    <property name="hibernate.format_sql">true</property>
    <property name="hibernate.use_sql_comments">true</property>

    <property name="hibernate.jdbc.batch_size">20</property>

    <property name="hibernate.cache.use_second_level_cache">true</property>
    <property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>
    <property name="net.sf.ehcache.configurationResourceName">/ehcache.xml</property>


    <!-- mapping files -->
    <mapping resource="domain.hbm.xml"/>

     <!--cache entities -->
    <class-cache class="com.wgu.domain.Attribute" usage="read-write"/>
    <collection-cache collection="com.wgu.domain.AttributeType.values" usage="read-write"/>

  </session-factory>
</hibernate-configuration>
 

 

For more details on the meaning of configuration properties,  please rerfer to Hibernate session configuration specification.

 

Integrate Hibernate with Spring

You may find out there are some critical properties missed in previous configuration file:

hibernate.connection.driver_classJDBC driver class
hibernate.connection.urlJDBC URL
hibernate.connection.usernamedatabase user
hibernate.connection.passworddatabase user password
hibernate.connection.pool_sizemaximum number of pooled connections

That's because we use hibernate with Spring.

 

Configure SessionFactory

 

  <bean id="mySessionFactory" lazy-init="true" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation">
      <value>classpath:/hibernate.cfg.xml</value>
    </property>
    <property name="hibernateProperties">
      <ref bean="hibernateProperties"/>
    </property>
    <property name="dataSource">
      <ref bean="DataSource"/>
    </property>
    <property name="lobHandler">
      <ref bean="LobHandler"/>
    </property>
  </bean>
 

 

Configure Datasource

JDBC Connection Configuration

<bean id="DataSource" lazy-init="true"
	class="org.apache.commons.dbcp.BasicDataSource" autowire="default"
	dependency-check="default">
	<property name="driverClassName">
		<value>oracle.jdbc.driver.OracleDriver
		</value>
	</property>
	<property name="url">
		<value>jdbc:oracle:thin:@${db.host}:${db.port}:${db.service}
		</value>
	</property>
	<property name="username">
		<value>${db.user}</value>
	</property>
	<property name="password">
		<value>${db.password}</value>
	</property>
	<property name="maxActive">
		<value>100</value>
	</property>
	<property name="defaultAutoCommit">
		<value>false</value>
	</property>
	<property name="testOnBorrow">
		<value>true</value>
	</property>
	<property name="minEvictableIdleTimeMillis">
		<value>5000</value>
	</property>
	<property name="timeBetweenEvictionRunsMillis">
		<value>10000</value>
	</property>
	<property name="numTestsPerEvictionRun">
		<value>5</value>
	</property>
	<property name="validationQuery">
		<value>SELECT COUNT(*) FROM DUAL</value>
	</property>
</bean>

 

Datasource JNDI Configuration

  <bean id="hibernateProperties" class="java.util.Properties">
    <constructor-arg index="0">
      <props>
        <prop key="hibernate.show_sql">false</prop>
        <prop key="hibernate.connection.datasource">java:comp/env/jdbc/dataSource</prop>
        <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</prop>
      </props>
    </constructor-arg>
  </bean>

  <jee:jndi-lookup id="DataSource" jndi-name="dataSource"/>
 

 

Configure Hibernate use SSL through JDBC connection

<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
    <property name="URL"><value><!-- JDBC URL that specifies SSL connection --></value></property>
    <!-- other relevant properties, like user and password -->
    <property name="connectionProperties>
        <value>
            oracle.net.ssl_cipher_suites: (ssl_rsa_export_with_rc4_40_md5, ssl_rsa_export_with_des40_cbc_sha)
            oracle.net.ssl_client_authentication: false
            oracle.net.ssl_version: 3.0
            oracle.net.encryption_client: REJECTED 
            oracle.net.crypto_checksum_client: REJECTED
        </value>
    </property>
</bean>
 Please refer to  stackoverflow.com.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值