<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect">
<diskStore path="java.io.tmpdir"/><!-- java.io.tmpdir -->
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="1200"
memoryStoreEvictionPolicy="LRU"
/>
<!-- com.legentec.netbar.object.NmClientInfo -->
<!-- 缓存最大数目 -->
<!-- 缓存是否持久 -->
<!-- 是否保存到磁盘,当系统当机时-->
<!-- 当缓存闲置n秒后销毁 -->
<!-- 当缓存存活n秒后销毁-->
<!-- 默认策略是LRU(最近最少使用),也有其他的策略,如:FIFO(先进先出策略),LFU(最少使用策略) -->
</ehcache>
ehcache.xml
<?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>
<!--描述一个持久化类 name属性为持久化类的全名、table 该持久化类对应的表名 默认情况下为类名、catalog 为数据库的名称-->
<class name="com.legentec.netbar.object.NmNetbarNotice" table="Nm_NetBar_Notice ">
<cache usage="read-only" />
<!-- id对应表中的主键 、name为持久化类中属性的名称、length 为对应数据库表中相应字段的长度、column 属性的名称对应的表的字段名称 不写则默认和属性的名称一致 -->
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="marker_id" column="MARKER_ID" ></property>
<property name="notice_time" column="NOTICE_TIME"></property>
<property name="title" column="TITLE"></property>
<property name="message" column="MESSAGE"></property>
</class>
</hibernate-mapping>
hibernate.cfg.xml
public NmClientInfo selClintInfoByMarkerId(long markerId)
{
NmClientInfo nmClientInfo = null;
Session session = null;
try
{
session = this.getHibernateTemplate().getSessionFactory().openSession();
nmClientInfo = (NmClientInfo) session.load(NmClientInfo.class, markerId);
session.clear();
session.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return nmClientInfo;
}
public List<NmNetbarNotice> getNetbarNoticeList(long markerId,int pageIndex, int singlePageCount){
List<NmNetbarNotice> nmNetbarNotices = new ArrayList<NmNetbarNotice>();
try {
Session session = this.getHibernateTemplate().getSessionFactory().openSession();
Query query = session.createSQLQuery("SELECT * FROM (" +
" SELECT t.* FROM ( SELECT * FROM Nm_NetBar_Notice WHERE MARKER_ID= ? ORDER BY id desc )t )" +
" WHERE ROWNUM >(?-1)*? and ROWNUM <=?*?").addEntity(NmNetbarNotice.class);
query.setLong(0, markerId);
query.setInteger(1, pageIndex);
query.setInteger(2, singlePageCount);
query.setInteger(3, pageIndex);
query.setInteger(4, singlePageCount);
query.setCacheable(true); //缓存
nmNetbarNotices = query.list();
session.clear();
session.close();
} catch (Exception e) {
e.printStackTrace();
}
return nmNetbarNotices;
}