<!--
配置缓存插件
-->
<
property
name
=
"hibernate.cache.provider_class"
>
org.hibernate.cache.EhCacheProvider
</
property
>
|
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<!
DOCTYPE
hibernate-mapping
PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<
hibernate-mapping
>
<
class
name
=
"org.qiujy.domain.cachedemo.Category"
table
=
"categories"
>
<!—
配置缓存
,
必须紧跟在
class
元素后面
对缓存中的
Category
对象采用读写型的并发访问策略
-->
<
cache
usage
=
"read-write"
/>
<
id
name
=
"id"
type
=
"java.lang.Long"
>
<
column
name
=
"id"
/>
<
generator
class
=
"native"
/>
</
id
>
<!--
配置版本号
,
必须紧跟在
id
元素后面
-->
<
version
name
=
"version"
column
=
"version"
type
=
"java.lang.Long"
/>
<
property
name
=
"name"
type
=
"java.lang.String"
>
<
column
name
=
"name"
length
=
"32"
not-null
=
"true"
/>
</
property
>
<
property
name
=
"description"
type
=
"java.lang.String"
>
<
column
name
=
"description"
length
=
"255"
/>
</
property
>
<
set
name
=
"products"
table
=
"products"
cascade
=
"all"
inverse
=
"true"
>
<!-- Hibernate
只会缓存对象的简单属性的值
,
要缓存集合属性
,
必须在集合元素中也加入
<cache>
子元素
而
Hibernate
仅仅是把与当前持久对象关联的对象的
OID
存放到缓存中。
如果希望把整个关联的对象的所有数据都存入缓存
,
则要在相应关联的对象的映射文件中配置
<cache>
元素
-->
<
cache
usage
=
"read-write"
/>
<
key
column
=
"categoryId"
not-null
=
"true"
/>
<
one-to-many
class
=
"org.qiujy.domain.cachedemo.Product"
/>
</
set
>
</
class
>
</
hibernate-mapping
>
|
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<!
DOCTYPE
hibernate-mapping
PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<
hibernate-mapping
>
<
class
name
=
"org.qiujy.domain.cachedemo.Product"
table
=
"products"
>
<
cache
usage
=
"read-write"
/>
<
id
name
=
"id"
type
=
"java.lang.Long"
>
<
column
name
=
"id"
/>
<
generator
class
=
"native"
/>
</
id
>
<!--
配置版本号
,
必须紧跟在
id
元素后面
-->
<
version
name
=
"version"
column
=
"version"
type
=
"java.lang.Long"
/>
<
property
name
=
"name"
type
=
"java.lang.String"
>
<
column
name
=
"name"
length
=
"32"
not-null
=
"true"
/>
</
property
>
<
property
name
=
"description"
type
=
"java.lang.String"
>
<
column
name
=
"description"
length
=
"255"
/>
</
property
>
<
property
name
=
"unitCost"
type
=
"java.lang.Double"
>
<
column
name
=
"unitCost"
/>
</
property
>
<
property
name
=
"pubTime"
type
=
"java.util.Date"
>
<
column
name
=
"pubTime"
not-null
=
"true"
/>
</
property
>
<
many-to-one
name
=
"category"
column
=
"categoryId"
class
=
"org.qiujy.domain.cachedemo.Category"
cascade
=
"save-update"
not-null
=
"true"
>
</
many-to-one
>
</
class
>
</
hibernate-mapping
>
|
<
ehcache
>
<
diskStore
path
=
"c:\\ehcache\"
/>
<
defaultCache
maxElementsInMemory
=
"10000"
eternal
=
"false"
timeToIdleSeconds
=
"120"
timeToLiveSeconds
=
"120"
overflowToDisk
=
"true"
/>
<!--
设置
Category
类的缓存的数据过期策略
-->
<
cache
name
=
"org.qiujy.domain.cachedemo.Category"
maxElementsInMemory
=
"100"
eternal
=
"true"
timeToIdleSeconds
=
"0"
timeToLiveSeconds
=
"0"
overflowToDisk
=
"false"
/>
<!--
设置
Category
类的
products
集合的缓存的数据过期策略
-->
<
cache
name
=
"
org.qiujy.domain.cachedemo.Category.products
"
maxElementsInMemory
=
"500"
eternal
=
"false"
timeToIdleSeconds
=
"300"
timeToLiveSeconds
=
"600"
overflowToDisk
=
"true"
|