ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <erlend.bjo...@aftenposten.no>
Subject SQLMap and OSCACHE unwanted behavior with hierarchy of objects.
Date Thu, 21 Apr 2005 17:50:59 GMT
Hi there!
Today I introduced OSCACHE in our SQLMap application, what a performace boost! :-)
I have some heavy queries, doing a lot of stuff, some is' pretty static, so bringing
in the cache is a nice feature.
Anyway I have discovered something realy strange I think, not sure where the "error" or
smart behavior is located, it's most unwanted since I have to write extra code to avoid it!
I'm working with hierarchy of categories, pointing to itself. The CategoryBean is
one of our value/transfer objects.
public class CategoryBean extends GeneralBean implements Serializable {
    private List subCategories;     // List of CategoryBean's ....
So what I do, I query the database to retrieve two levels of the hierarchy in a Oracle
database, returning 21 rows, where the first row is the root.
After the rows are returned from this query:
list = Collections.synchronizedList(sqlMap.queryForList("retrieveFirstPageCategories", null));
              (Have tried with/without synchronized to see if that helped = NOT :)
The query using this cache:
    <cacheModel id="category-cache" type="OSCACHE">
        <flushInterval hours="1"/>
        <flushOnExecute statement="insertCategory"/>
        <flushOnExecute statement="updateCategory"/>

I create the rootBean of the first row in the list, then add the other 20 rows to the subCategories.
So far so good, BUT when I run the query twice or more when the OSCACHE is up and running
(sqlMap has returned the connection to the pool between the runs) .... I still get 21 rows
the same query back, BUT now the first one in the list (the rootBean) already have those 20
listed, I added in the first run ! That's impressive :-) but most unwanted behavior since
 I have to write extra 
code to not add those 20 rows again = 40 subCategories... Of course after 3 runs, 60 subCategories
How can I avoid this "smart" behavior ??? hmm Is it a bug ? I guess not, something 
to tune in SQLMap, OSCACHE ? or ? hmmm Some guy here mention something about
adding the hashCode() and equals() to my CategoryBean ... is that the rigth path to go ? 
He have already added the hashCode and equals, but a "simple" logic ... what's requried
to avoid this smart behavior ?
Thanks for any help!
Best regards,
Erlend Bjørge

View raw message