-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ehcache and queries
PostPosted: Tue Mar 29, 2005 4:26 am 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
Hi,
I'm using hibernate on a production server since a few days now.
It's all fine except for one thing: I make 2 queries:
Code:
session.createQuery("select c " +
                    "from Catalog c " +
                    "   join fetch c.products p " +
                    "   join p.options o " +
                    "where c.id = :id " +
                    "   and o.stockAvailable > 0")
                    .setCacheable(true)
                    .setCacheRegion("Category.Level2");
and
                  session.createQuery("select c " +
                        "from Catalog c " +
                        "   join fetch c.children child " +
                        "where c.id = :id " +
                        "   and child.id in " +
                        "   (select catalog.id " +
                        "       from Catalog catalog " +
                        "       left join catalog.products p " +
                        "       left join p.options o " +
                        "       where catalog.parentCatalog.id = :id" +
                        "           and (o.stockAvailable > 0 " +
                        "               or exists elements(catalog.children)) ) ")
                    .setCacheable(true)
                    .setCacheRegion("Category.Level2");


If query 1 returns null, we use query 2.

But now once in a while, since in production, I get Category.children with Catalog's having no products nor children categories...

I suppose it uses a cached version of Category that comes from god knows where...
I've put that in the caching:
Code:
    <cache name="be.barracuda.model.products.Category"
        maxElementsInMemory="500"
        eternal="false"
        timeToIdleSeconds="180"
        timeToLiveSeconds="300"
        overflowToDisk="false"
        />
    <cache name="be.barracuda.model.products.Category.children"
        maxElementsInMemory="0"
        eternal="false"
        timeToIdleSeconds="0"
        timeToLiveSeconds="0"
        overflowToDisk="false"
        />
    <cache name="be.barracuda.model.products.Category"
        maxElementsInMemory="500"
        eternal="false"
        timeToIdleSeconds="180"
        timeToLiveSeconds="300"
        overflowToDisk="false"
        />
    <cache name="Category.Level1"
        maxElementsInMemory="100"
        eternal="false"
        timeToLiveSeconds="90"
        overflowToDisk="false"
        />
    <cache name="Category.Level2"
        maxElementsInMemory="100"
        eternal="false"
        timeToLiveSeconds="90"
        overflowToDisk="false"
        />


and the hibernate's category mapping file:
Code:
    <class name="Catalog" table="catalogs">
        <cache usage="read-write"/>
        <id name="id" type="long" column="id">
            <generator class="sequence">
                <param name="sequence">catalogs_id_seq</param>
            </generator>
        </id>
        <map name="descriptions" table="catalogs_i18n" lazy="false" batch-size="3">
            <cache usage="read-write"/>
            <key column="id_catalog"/>
            <index column="locale" type="string" length="2"/>
            <element column="description" type="string"/>
        </map>
        <set name="children" lazy="true" outer-join="true" order-by="ord asc" batch-size="10">
            <cache usage="read-write"/>
            <key column="id_parent"/>
            <one-to-many class="Catalog"/>
        </set>
        <property name="key" column="key" type="string" unique="true" not-null="true" length="128"/>
        <property name="order" column="ord" type="integer"/>
        <many-to-one name="parentCatalog" column="id_parent" class="Catalog"/>
        <set name="products" table="products_catalogs" lazy="true">
            <cache usage="read-write"/>
            <key column="id_catalog"/>
            <many-to-many class="Product" column="id_product"/>
        </set>
        <map name="labels" table="catalogs_i18n" lazy="false" batch-size="3">
            <cache usage="read-write"/>
            <key column="id_catalog"/>
            <index column="locale" type="string" length="2"/>
            <element column="label" type="string" length="1024"/>
        </map>
    </class>


Categories in Product is also mapped as lazy BUT I realize that I have no inverse end!
Same thing for parentCatalog<1-*>children...

Any clue is welcome! Thanks
Alex
[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.