发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 CQRS 扩展性 并发编程 事件溯源 分布式 SOA

Using JCS in Hibernate

2003-09-11 21:19
赞助商链接

Hi all,

I have a question about the JCS, since I haven't used it before, I don't know how it works.

We have a table in our database, and its data rarely changes, so it is good for caching. I tried to put <jcs-cache usage="read-write" /> to my .hbm.xml file, but I don't know how to test it to make sure its data is from cache not from database?

Thanks a lot!

2003-09-12 09:02

设置hibernate.show_sql true
如果出现SQL语句,则说明是从数据库取得,
没有则是从CACHE(或者只是查询出id)

2003-09-12 22:26

Thank you yehs220 for replying.

I tried what you said, but it always show me the SQL statements, so that means the data is from database? I did use <jcs-cache usage="nonstrict-read-write"/> in my .hbm.xml, I do not know what is wong with it? If you have a chance, could you take a look,

P.S, someone told me to turn on log4j.logger.net.sf.hibernate.cache=debug, I also tried this, it showed me something like "Cache new", don't know if the cache has been used.

Here is my .hbm.xml file

*****************************************************
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.hibernate.Alias" table="alias">
<jcs-cache usage="read-write"/>
<composite-id name="id">
<key-property name="firm" column="firm"/>
<key-property name="userid" column="userid"/>
<key-property name="alias" column="alias"/>
</composite-id>

<property name="sub_client" column="sub_client"/>
<property name="update_ident" column="update_ident"/>
</class>

</hibernate-mapping>
<!-- parsed in 10ms -->
**********************************************************

Here is the code I load the object:
**********************************************************

public void listAlias() throws HibernateException
{
Session session = sessionFactory.openSession();

Iterator iter = session.iterate("from com.hibernate.Alias as alias");

while (iter.hasNext())
{
Alias myAlias = (Alias) iter.next();
System.out.println("-------client is----" + myAlias.getClient());
System.out.println("-------subclient is----" + myAlias.getSub_client());
session.evict(myAlias);
}

session.close();
}

**********************************************************

Main()
---------------------------------------------------------------------------------

hiberTest.listAlias();

hiberTest.listAlias();

----------------------------------------------------------------------------------

Thanks for helping!

2003-09-13 01:26

I found if I use session.load(.....), it will hit the cache, I don't know why iterator does not work here? anybody knows?

Thanks

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系反馈 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com