Hibernate3+ehcache+c3p0+jtds+MSSQL

首先把該放的jar檔案都放到CLASSPATH內,稍作修改程式碼,以及Hibernate定義後,
就可以使用Hibernate3+ehcache+c3p0+jtds+MSSQL
Hibernate資料模型物件撰寫範例(只貼上Parent端)


<hibernate-mapping default-lazy="true" package="com.pcyi.DAO">
  <class lazy="true" name="Parent" table="walkone_parent">
  <cache usage="read-write">  
    <id column="id" name="id" type="integer">
      <generator class="native">
    </generator></id>
    
    
    <set cascade="all" inverse="true" lazy="true" name="children" order-by="id DESC">
      <key column="ref_parent_id">
      <one -to-many="-to-many" class="Children">
    </one></key></set>
  </cache></class>
</hibernate-mapping>



Hibernate設定內容



<hibernate-configuration>
  <session-factory name="walkOne">
    
    <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
    
    <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
    
    <property name="connection.url">jdbc:jtds:sqlserver://localhost:1433/dbname;charset=utf-8</property>
    
    <property name="connection.username">id</property>
    
    <property name="connection.password">pw</property>
    
    
    
    <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
    
    <property name="hibernate.cache.use_query_cache">true</property>
    
    <property name="show_sql">false</property>
    
    <property name="format_sql">false</property>
    

    
    <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
    <property name="c3p0.acquire_increment">0</property>
    
    <property name="c3p0.idle_test_period">100</property> 
    <property name="c3p0.max_size">100</property> 
    <property name="c3p0.max_statements">0</property> 
    <property name="c3p0.min_size">10</property>
     
    <property name="c3p0.timeout">300</property> 
  </session-factory>
</hibernate-configuration>

 
ehcache設定內容


<ehcache>
  <diskstore path="java.io.tmpdir/ehcache/app1">
    <defaultcache eternal="false" maxelementsinmemory="10000" overflowtodisk="true" timetoidleseconds="120" timetoliveseconds="120">
      <cache eternal="false" maxelementsinmemory="5" name="org.hibernate.cache.StandardQueryCache" overflowtodisk="true" timetoliveseconds="120" />
      <cache eternal="false" maxelementsinmemory="5000" name="org.hibernate.cache.UpdateTimestampsCache" overflowtodisk="true"/>
    </defaultcache>
  </diskstore>
</ehcache>

留言