Configure the level-2 Cache ehcache and c3p0 connection pool in hibernate to reverse create a database

Source: Internet
Author: User

-------------------- * 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. Connection. provider_class">
Org. hibernate. Connection. c3p0connectionprovider
</Property>
<Property name = "hibernate. bytecode. use_reflection_optimizer"> false </property>
<! -- When the connections in the connection pool are used up, c3p0 obtains the new connections -->
<Property name = "hibernate. c3p0. acquire_increment"> 2 </property>
<! -- Check idle connections in the connection pool every 100 seconds. Unit: seconds -->
<Property name = "hibernate. c3p0. idle_test_period"> 100 </property>
<! -- Maximum number of connections -->
<Property name = "hibernate. c3p0. max_size"> 30 </property>
<! -- Maximum number of preparedstatement -->
<Property name = "hibernate. c3p0. max_statements"> 0 </property>
<! -- Minimum connections -->
<Property name = "hibernate. c3p0. min_size"> 10 </property>
<! -- Get the connection timeout time. If the timeout value exceeds this time, an exception is thrown, in milliseconds. -->
<Property name = "hibernate. c3p0. Timeout"> 100 </property>

<! -- Enable hibernate second-level cache -->
<Property name = "hibernate. cache. use_second_level_cache"> true </property>

<! -- Specify that hibernate uses ehcache cache -->
<Property name = "hibernate. cache. provider_class"> org. hibernate. cache. ehcacheprovider </property>
<Property name = "hibernate. cache. use_query_cache"> true </property>
<Property name = "hibernate. cglib. use_reflection_optimizer"> true </property>


<Property name = "hibernate. Connection. driver_class"> org. gjt. Mm. MySQL. Driver </property>
<Property name = "hibernate. Connection. Password"> 333 </property>
<Property name = "hibernate. Connection. url"> JDBC: mysql: // localhost/wis14? Autoreconnect = true </property>
<Property name = "hibernate. Connection. username"> root </property>
<Property name = "hibernate. hbm2ddl. Auto"> Update </property>
<Property name = "hibernate. dialect"> org. hibernate. dialect. mysqldialect </property>
<Property name = "hibernate. show_ SQL"> true </property>
<Mapping Resource = "com/nen/CN/util/eiptbluser2.hbm. xml"/>
</Session-factory>
</Hibernate-configuration>

 

 

----------------------------- Ehcache. xml ---------------------------------------------------

<Ehcache>

<! -- Sets the path to the directory where cache. data files are created.

If the path is a Java System property it is replaced
Its value in the running VM.

The following properties are translated:
User. Home-user's home directory
User. dir-user's current working directory
Java. Io. tmpdir-default temp file path -->
<Diskstore Path = "Java. Io. tmpdir"/>


<! -- Default cache configuration. These will applied to caches programmatically created through
The cachemanager.

The following attributes are required for defaultcache:

Maxinmemory-sets the maximum number of objects that will be created in memory
Eternal-sets whether elements are eternal. If eternal, timeouts are ignored and the element
Is never expired.
Timetoidleseconds-sets the time to idle for an element before it expires. is only used
If the element is not eternal. idle time is now-Last accessed time
Timetoliveseconds-sets the time to live for an element before it expires. is only used
If the element is not eternal. TTL is now-creation time
Overflowtodisk-sets whether elements can overflow to disk when the in-memory cache
Has reached the maxinmemory limit.

-->
<Defaultcache
Maxelementsinmemory = "10000"
Eternal = "false"
Timetoidleseconds = "120"
Timetoliveseconds = "120"
Overflowtodisk = "true"
/>

<! -- Predefined caches. Add your cache configuration settings here.
If you do not have a configuration for your cache a warning will be issued when
Cachemanager starts

The following attributes are required for defaultcache:

Name-sets the name of the cache. This is used to identify the cache. It must be unique.
Maxinmemory-sets the maximum number of objects that will be created in memory
Eternal-sets whether elements are eternal. If eternal, timeouts are ignored and the element
Is never expired.
Timetoidleseconds-sets the time to idle for an element before it expires. is only used
If the element is not eternal. idle time is now-Last accessed time
Timetoliveseconds-sets the time to live for an element before it expires. is only used
If the element is not eternal. TTL is now-creation time
Overflowtodisk-sets whether elements can overflow to disk when the in-memory cache
Has reached the maxinmemory limit.

-->

<! -- Sample cache named samplecache1
This cache contains a maximum in memory of 10000 elements, and will expire
An element if it is idle for more than 5 minutes and lives for more
10 minutes.

If there are more than 10000 elements it will overflow to
Disk cache, which in this configuration will go to wherever java. Io. tmp is
Defined on your system. On a standard Linux system this will be/tmp"
-->
<Cache name = "samplecache1"
Maxelementsinmemory = "10000"
Eternal = "false"
Timetoidleseconds = "300"
Timetoliveseconds = "600"
Overflowtodisk = "true"
/>

<! -- Sample cache named samplecache2
This cache contains 1000 elements. elements will always be held in memory.
They are not expired. -->
<Cache name = "samplecache2"
Maxelementsinmemory = "1000"
Eternal = "true"
Timetoidleseconds = "0"
Timetoliveseconds = "0"
Overflowtodisk = "false"
/> -->

<! -- Place configuration for your caches following -->

</Ehcache>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.