3 Nisan 2018 Salı

Hibernate hibernate.cfg.xml

Giriş
Şeklen şöyle
<hibernate-configuration>
  <session-factory>
    <property name="...">...</property>
    ...
    </session-factory>
</hibernate-configuration> 
Cache
Cache'i etkinleştirmek için şöyle yaparız.
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
HashTable için şöyle yaparız.
<!-- hibernate dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property> 
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver
</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@10.123.79.59:1521:georli04
</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>  
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory</property>

<!-- Automatic schema creation (begin) === -->      
<property name="hibernate.hbm2ddl.auto">none</property> 

<!-- Simple memory-only cache -->
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider</property>

 <!-- Enable Hibernate's automatic session context management -->
 <property name="current_session_context_class">thread</property>  

<mapping class="com.infy.entity.StudentEntity"/>
<mapping class="com.infy.entity.CourseEntity"/>  
EhCache

hibernate.cache.provider_class - Eski
Şöyle yaparız. net.sf.ehcache.hibernateEhCacheProvider deprecate edildiği için kullanılmamalı.
<!-- This is the provider for Ehcache provided by Hibernate, using the "old" SPI -->
<property name="hibernate.cache.provider_class"
  value="org.hibernate.cache.EhCacheProvider"/>
hibernate.cache.region.factory_class - Yeni
Bazı örneklerde net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory yerine Hibernate isim alanındaki org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory sınıfı kullanılıyor

Bazı örneklerde net.sf.ehcache.hibernate.EhCacheRegionFactory yerine Hibernate isim alanındaki org.hibernate.cache.ehcache.EhCacheRegionFactory sınıfı kullanılıyor.

Hibernate 4 ile Hibernate isim alanındakileri kullanmak lazım.

Örnek
Şöyle yaparız.
<property name="cache.region.factory_cla­ss">
  org.hibernate.cache.ehcache.Si­ngletonEhCacheRegionFactory</property>
Örnek
Şöyle yaparız.
<!-- The region factory property is the "new" property (for Hibernate 3.3 and above) -->
<property name="hibernate.cache.region.factory_class"
  value="net.sf.ehcache.hibernate.EhCacheRegionFactory">
Örnek
Şöyle yaparız.
<property name="hibernate.cache.region.factory_class">
        net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
</property>
<property name="hibernate.cache.provider_configuration">
    /ehcache.xml
</property>
<property name="hibernate.cache.use_second_level_cache">
    true
</property>
<property name="hibernate.cache.use_query_cache">
    true
</property>

Hiç yorum yok:

Yorum Gönder