ibatis缓存设置无效,是那里除了问题? 20
SqlMapConfig.xml<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEsqlMapConfigPUBLIC"-//ib...
SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<properties resource="jdbc.properties" />
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${jdbc.driverClassName}" />
<property name="JDBC.ConnectionURL" value="${jdbc.url}" />
<property name="JDBC.Username" value="${jdbc.username}" />
<property name="JDBC.Password" value="" />
</dataSource>
</transactionManager>
<sqlMap resource="ibatis/resources/User.xml" />
</sqlMapConfig>
User.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<typeAlias alias="User" type="ibatis.model.User" />
<cacheModel id="model-cache" type="MEMORY" >
<flushInterval seconds="60"/>
<flushOnExecute statement="updateProduct"/>
<property name="size" value="1000" />
</cacheModel>
<select id="getAllUsers" resultClass="User">
select *
from users
</select>
</sqlMap>
上面是我的配置信息。但是程序中查询的时候:
String config = "ibatis/SqlMapConfig.xml";
Reader reader = Resources.getResourceAsReader(config);
SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
List<User> list = sqlMap.queryForList("getAllUsers");
for (User user : list) {
System.out.println(user);
} list = sqlMap.queryForList("getAllUsers");
for (User user : list) {
System.out.println(user);
}list = sqlMap.queryForList("getAllUsers");
for (User user : list) {
System.out.println(user);
}list = sqlMap.queryForList("getAllUsers");
for (User user : list) {
System.out.println(user);
}
这是我查询的代码。在mysql日志中依然执行了4次查询语言。说明缓存设置没有生效。
这是为什么啊?我配置哪里出问题了吗 展开
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<properties resource="jdbc.properties" />
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${jdbc.driverClassName}" />
<property name="JDBC.ConnectionURL" value="${jdbc.url}" />
<property name="JDBC.Username" value="${jdbc.username}" />
<property name="JDBC.Password" value="" />
</dataSource>
</transactionManager>
<sqlMap resource="ibatis/resources/User.xml" />
</sqlMapConfig>
User.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<typeAlias alias="User" type="ibatis.model.User" />
<cacheModel id="model-cache" type="MEMORY" >
<flushInterval seconds="60"/>
<flushOnExecute statement="updateProduct"/>
<property name="size" value="1000" />
</cacheModel>
<select id="getAllUsers" resultClass="User">
select *
from users
</select>
</sqlMap>
上面是我的配置信息。但是程序中查询的时候:
String config = "ibatis/SqlMapConfig.xml";
Reader reader = Resources.getResourceAsReader(config);
SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
List<User> list = sqlMap.queryForList("getAllUsers");
for (User user : list) {
System.out.println(user);
} list = sqlMap.queryForList("getAllUsers");
for (User user : list) {
System.out.println(user);
}list = sqlMap.queryForList("getAllUsers");
for (User user : list) {
System.out.println(user);
}list = sqlMap.queryForList("getAllUsers");
for (User user : list) {
System.out.println(user);
}
这是我查询的代码。在mysql日志中依然执行了4次查询语言。说明缓存设置没有生效。
这是为什么啊?我配置哪里出问题了吗 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏20(财富值+成长值)
2个回答
展开全部
<!--别名-->
<alias>
<typeAlias alias="CaseSummary" type="Comit.TE.Web.Domain.Cases.CaseSummary, Comit.TE.Web.Domain" />
</alias>
<!--缓存模型-->
<cacheModels>
<cacheModel id="CaseSummaryCache" implementation="MEMORY">
<flushInterval hours="24"/>
<flushOnExecute statement="CaseSummary.AddCaseSummary"/>
<flushOnExecute statement="CaseSummary.UpdateCaseSummary"/>
<flushOnExecute statement="CaseSummary.DeleteCaseSummary"/>
<flushOnExecute statement="CaseSummary.DeleteCaseSummarys"/>
<flushOnExecute statement="CaseSummary.UpdateCaseSummaryName"/>
<property name="Type" value="WEAK"/>
</cacheModel>
</cacheModels>
<alias>
<typeAlias alias="CaseSummary" type="Comit.TE.Web.Domain.Cases.CaseSummary, Comit.TE.Web.Domain" />
</alias>
<!--缓存模型-->
<cacheModels>
<cacheModel id="CaseSummaryCache" implementation="MEMORY">
<flushInterval hours="24"/>
<flushOnExecute statement="CaseSummary.AddCaseSummary"/>
<flushOnExecute statement="CaseSummary.UpdateCaseSummary"/>
<flushOnExecute statement="CaseSummary.DeleteCaseSummary"/>
<flushOnExecute statement="CaseSummary.DeleteCaseSummarys"/>
<flushOnExecute statement="CaseSummary.UpdateCaseSummaryName"/>
<property name="Type" value="WEAK"/>
</cacheModel>
</cacheModels>
更多追问追答
追问
别名(alias) 在哪配置?有什么作用?
追答
就是一个类的别名
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询