Do you have this attribute defined in the setting element:
cacheModelsEnabled="true"
In the sqlMapConfig file?
On 6/2/08 3:23 PM, "andrew cooke" <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I have a very simple system, with two tables, related 1:many, and
> a single query which reads all entries from the outer join,
> returning a list of objects each of which contains a list of
> secondary objects from the "many" table.
>
> This all works fine.
>
> Now I have enabled caching, but am seeing:
> 1 - no difference in the logging
> 2 - different results if I repeat the query after modifying the
> database by hand (indicating that the database is being re-read)
>
> Note that in (2) the two reads are from the same Java thread,
> which pauses in a Thread.sleep(30000) while I delete data by hand
> using mysql from the command line. If caching was working I
> would expect the second read (ie the second call to
> sqlMap.queryForList) to return the same data as before, since
> iBatis does not "know" I deleted rows from a table).
>
> My Java code is read only - the only writing to the objects is
> done bu iBatis during bean assembly - and I have specified
> readOnly="true" on the cache.
>
> So why isn't the select being cached? Alternatively, if it is
> being cached, how do I verify it?
>
> I will include some relevant parts from the config and logs
> below. I tried serialize="true" too, just in case it would
> help (my understanding is it should not be needed for
> readOnly="true" and it made no difference).
>
> Any help appreciated,
> Thanks,
> Andrew
>
> <sqlMap namespace="kpi">
>
> <resultMap id="kpi-result" class="com.isti.kpidb.domain.Kpi"
> groupBy="id">
> <result property="id" column="kpi.kpi_id"/>
> <result property="title" column="kpi.title"/>
> <result property="description" column="kpi.description"/>
> <!-- this is the "many" defined elsewhere -->
> <result property="slpis" resultMap="slpi.slpi-result"/>
> </resultMap>
>
> <cacheModel id="kpi-cache" type="LRU" readOnly="true" serialize="true">
> <flushInterval hours="1"/>
> <!-- the select returns 16 lines -->
> <property name="size" value="20"/>
> </cacheModel>
>
> <select id="allKpis" resultMap="kpi-result" cacheModel="kpi-cache">
> SELECT *
> FROM kpis as kpi
> LEFT OUTER JOIN slpis as slpi
> ON kpi.kpi_id = slpi.kpi_id
> </select>
>
> </sqlMap>
>
> and the db config is just:
>
> <transactionManager type="JDBC" >
> <dataSource type="SIMPLE">
> <property name="JDBC.Driver" value="${driver}"/>
> <property name="JDBC.ConnectionURL" value="${url}"/>
> <property name="JDBC.Username" value="${username}"/>
> <property name="JDBC.Password" value="${password}"/>
> </dataSource>
> </transactionManager>
>
> The log looks liked this (even when the same query is re-run):
> 02-Jun-2008 17:13:34 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl debug
> FINE: Checked out connection 1420603736 from pool.
> 02-Jun-2008 17:13:34 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl debug
> FINE: {conn-100003} Connection
> 02-Jun-2008 17:13:34 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl debug
> FINE: {conn-100003} Preparing Statement: SELECT * FROM kpis as kpi
> LEFT OUTER JOIN slpis as slpi ON kpi.kpi_id = slpi.kpi_id
> 02-Jun-2008 17:13:34 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl debug
> FINE: {pstm-100004} Executing Statement: SELECT * FROM kpis as kpi
> LEFT OUTER JOIN slpis as slpi ON kpi.kpi_id = slpi.kpi_id
> 02-Jun-2008 17:13:34 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl debug
> FINE: {pstm-100004} Parameters: []
> 02-Jun-2008 17:13:34 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl debug
> FINE: {pstm-100004} Types: []
> 02-Jun-2008 17:13:34 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl debug
> FINE: {rset-100005} ResultSet
> 02-Jun-2008 17:13:34 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl debug
> FINE: {rset-100005} Header: [kpi.kpi_id, kpi.title, kpi.description,
> slpi.slpi_id, slpi.title, slpi.description]
> 02-Jun-2008 17:13:34 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl debug
> FINE: {rset-100005} Result: [A, A, KPI A description, A1, A1, SLPI A1
> description]
> etc.
>