-->
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.  [ 14 posts ] 
Author Message
 Post subject: Problem with query caching in Hibernate 2.1.3
PostPosted: Mon May 10, 2004 7:08 am 
Newbie

Joined: Wed Jan 07, 2004 11:34 am
Posts: 11
Location: London, UK
I've got a problem with 2.1.3 query caching - it doesn't seem to work for me (everything was fine under 2.1.2). I've stripped some test code out of my WL environment and brought it down to a minimal set of code -

Code:
package test;

import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.cfg.Configuration;

import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;

public class HibernateBug {
    public static void main(String[] args) {
        BasicConfigurator.configure();
        Logger.getRootLogger().setLevel(Level.INFO);

        final HibernateBug thisInstance = new HibernateBug();

        try {
            final SessionFactory sf = thisInstance.initializeHibernate().buildSessionFactory();
            thisInstance.testRunQuery(sf);
            thisInstance.testRunQuery(sf);
        } catch (HibernateException e) {
            e.printStackTrace();
        }
    }

    final Configuration initializeHibernate() throws HibernateException {
        final Properties props = new Properties();
        props.put("hibernate.connection.driver_class", "weblogic.jdbc.sqlserver.SQLServerDriver");
        props.put("hibernate.connection.url", "jdbc:bea:sqlserver://localhost:1433;DatabaseName=test");
        props.put("hibernate.connection.username", "test");
        props.put("hibernate.connection.password", "test");
        props.put("hibernate.c3p0.minPoolSize", "5");
        props.put("hibernate.c3p0.maxPoolSize", "20");
        props.put("hibernate.c3p0.timeout", "1800");
        props.put("hibernate.c3p0.max_statement", "50");
        props.put("hibernate.dialect", "net.sf.hibernate.dialect.SybaseDialect");
        props.put("hibernate.use_outer_join", "true");
        props.put("hibernate.show_sql", "true");
        props.put("hibernate.cache.use_query_cache", "true");
        props.put("hibernate.transaction.factory_class", "net.sf.hibernate.transaction.JDBCTransactionFactory");

        return new Configuration().setProperties(props).addClass(SystemUser.class);
    }

    final void testRunQuery(final SessionFactory sf) throws HibernateException {
        final Session s = sf.openSession();

        try {
            System.out.println((SystemUser)(s.getNamedQuery("SystemUser.by.lastName").setParameter("lastName", "Riordan").
                    setCacheable(true).uniqueResult()));
        } finally{
            s.close();
        }
    }
}



mapping file -

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

<hibernate-mapping>
    <class
        name="test.SystemUser"
        table="SystemUser"
        mutable="true"
        lazy="true"
        >
        <cache usage="nonstrict-read-write"/>
        <id name="userId" type="integer" unsaved-value="0" access="field">
            <generator class="identity" />
        </id>
        <version name="version" access="field" />
        <property name="firstName" type="string" length="100" not-null="true" access="field" />
        <property name="lastName" type="string" length="100" not-null="true" access="field" />
    </class>

    <!-- Pre-packaged queries -->
    <query name="SystemUser.by.lastName"><![CDATA[
        from test.SystemUser user
        where user.lastName = :lastName
    ]]>
    </query>
</hibernate-mapping>


Under 2.1.2 this is the output -

Code:
1454 [main] INFO net.sf.hibernate.cache.UpdateTimestampsCache  - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
1454 [main] WARN net.sf.ehcache.hibernate.Plugin  - Could not find configuration for net.sf.hibernate.cache.UpdateTimestampsCache. Configuring using the defaultCache settings.
1454 [main] INFO net.sf.hibernate.cache.QueryCache  - starting query cache at region: net.sf.hibernate.cache.QueryCache
1454 [main] WARN net.sf.ehcache.hibernate.Plugin  - Could not find configuration for net.sf.hibernate.cache.QueryCache. Configuring using the defaultCache settings.
Hibernate: select systemuser0_.userId as userId, systemuser0_.version as version, systemuser0_.firstName as firstName, systemuser0_.lastName as lastName from SystemUser systemuser0_ where (systemuser0_.lastName=? )
SystemUser:[1,0,Nick,Riordan]
1688 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter  - SQL Warning: 0, SQLState:
1688 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter  - [BEA][SQLServer JDBC Driver][SQLServer]Changed database context to 'test'.
1688 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter  - SQL Warning: 0, SQLState:
1688 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter  - [BEA][SQLServer JDBC Driver][SQLServer]Changed language setting to us_english.
SystemUser:[1,0,Nick,Riordan]


Under 2.1.3 this is the output -

Code:
1656 [main] INFO net.sf.hibernate.cache.UpdateTimestampsCache  - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
1656 [main] WARN net.sf.ehcache.hibernate.Plugin  - Could not find configuration for net.sf.hibernate.cache.UpdateTimestampsCache. Configuring using the defaultCache settings.
1656 [main] INFO net.sf.hibernate.cache.QueryCache  - starting query cache at region: net.sf.hibernate.cache.QueryCache
1656 [main] WARN net.sf.ehcache.hibernate.Plugin  - Could not find configuration for net.sf.hibernate.cache.QueryCache. Configuring using the defaultCache settings.
Hibernate: select systemuser0_.userId as userId, systemuser0_.version as version, systemuser0_.firstName as firstName, systemuser0_.lastName as lastName from SystemUser systemuser0_ where (systemuser0_.lastName=? )
SystemUser:[1,0,Nick,Riordan]
1844 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter  - SQL Warning: 0, SQLState:
1844 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter  - [BEA][SQLServer JDBC Driver][SQLServer]Changed database context to 'test'.
1844 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter  - SQL Warning: 0, SQLState:
1844 [main] WARN net.sf.hibernate.util.JDBCExceptionReporter  - [BEA][SQLServer JDBC Driver][SQLServer]Changed language setting to us_english.
Hibernate: select systemuser0_.userId as userId, systemuser0_.version as version, systemuser0_.firstName as firstName, systemuser0_.lastName as lastName from SystemUser systemuser0_ where (systemuser0_.lastName=? )
SystemUser:[1,0,Nick,Riordan]


Note that the select gets run twice under 2.1.3. Is anyone else seeing this problem?

- Nick


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Not all Cache provide Query cache capability. Check the reference guide.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 12:48 pm 
Newbie

Joined: Wed Jan 07, 2004 11:34 am
Posts: 11
Location: London, UK
emmanuel wrote:
Not all Cache provide Query cache capability. Check the reference guide.


Hi Emmanuel,

I'm using the ehcache. Also it worked in 2.1.2 and doesn't work in 2.1.3 (see posting above).

Also - you get an exception from the setCacheable() if the provider doesn't support query caching (e.g. TreeCache - which doesn't support timestamps).

The more I investigate, the more I'm convinced this is a bug introduced in 2.1.3.

- Nick


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 1:46 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
I have found the same behavior: Query Cache that worked in 2.1.2 no longer works in 2.1.3.
By no longer works, I mean that every query is a cache miss. The queries work, and are put into the cache (size of the Query cache region grows), but the same query (from the same code) registers a miss every time.
-Michael Greer


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 1:50 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
I tried replacing ecache 0.7 with 0.6, but the behavior remains changed.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 1:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The Query Cache works for me, Hibernate 2.1.3, EHCache. Please submit a trivial test case to JIRA.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 1:58 pm 
Newbie

Joined: Wed Jan 07, 2004 11:34 am
Posts: 11
Location: London, UK
Yep - I tried that too. In fact I ran 2.1.2 with all the supporting jars from 2.1.3 and 2.1.2 still works fine and 2.1.3 doesn't.

We're stuck on this at the moment. We need 2.1.3 because we need two other bug fixes - the one that corrects problems with Tangosol and the fixed JCA support for Weblogic.

Tomorrow I'll try to dig through the code some more. The cache package doesn't seem to have changed much - so I'm starting with the Session handling. Unfortunately SessionImpl has been going through a lot of change recently and diffing in CVS is full of "noise".

This is painful.

- Nick


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 2:00 pm 
Newbie

Joined: Wed Jan 07, 2004 11:34 am
Posts: 11
Location: London, UK
christian wrote:
The Query Cache works for me, Hibernate 2.1.3, EHCache. Please submit a trivial test case to JIRA.


Hi Christian,

Is this running my code/config above? Or is it running another config?

Cheers - Nick


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 2:20 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
My own tests, but it is the same. Can you try CVS v21branch current?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 2:27 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Oh, i got it. It's a problem with bind parameters. Please add a JIRA issue.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 4:02 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
I added it: HB-943


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 4:17 pm 
Newbie

Joined: Wed Jan 07, 2004 11:34 am
Posts: 11
Location: London, UK
Thanks Michael,

Didn't get a chance to post before heading home.

- Nick


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 5:19 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Fixed.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 1:43 am 
Newbie

Joined: Wed Jan 07, 2004 11:34 am
Posts: 11
Location: London, UK
Hi Christian,

Many thanks for the prompt fix. Will try it out today.

- Nick


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

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.