hi, trying to get some stuf in to secondary cache. secondary cachng seems to work fine automatically when i find stuff by pk (the timings get better).
the data i am reading is immutable, but i need to access it by a unique value that is not the primary key (don't ask). as you can see below the data is cached in the read only cache. but hib is looking for it in the query cache.
if i change mutable to true, i get the same results.
if i change cach to read-write or change both, i get:
01:20:39,430 DEBUG SQL:237 - select location0_.db_id as db_id, ...
01:20:39,590 DEBUG QueryCache:46 - caching query results in region: net.sf.hibernate.cache.QueryCache
01:20:39,700 INFO LocTestCase:258 - l is: loc.hibernate.Location@1af33d6[dbId=78295]
01:20:39,700 DEBUG QueryCache:61 - checking cached query results in region: net.sf.hibernate.cache.QueryCache
01:20:39,700 DEBUG QueryCache:64 - query results were not found in cache
01:20:39,700 DEBUG SQL:237 - select location0_.db_id as db_id, ...
is there a way to tell the query to use the read only cache or am i barking up the wrong tree? if so, what is it's name for setCacheRegion()?
would something like the code below help?
session.connection().setReadOnly(true);
session.setFlushMode(FlushMode.NEVER);
or will this have no effect on secondary-cache?
any pointers will be appreciated.
thanks
Hibernate version:
2.1.3
Mapping documents:
<?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>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class name='loc.hibernate.Location' table='location' mutable='false' >
<cache usage="read-only"/>
<id column='db_id' name='dbId' type='java.lang.Integer'>
<generator class='assigned' />
</id>
<property column='port_code' length='20' name='portCode' not-null='true' type='java.lang.String' unique='true' />
<property column='port_name' length='100' name='portName' not-null='true' type='java.lang.String' />
<property column='state_province' length='20' name='stateProvince' not-null='true' type='java.lang.String' />
<property column='country' length='20' name='country' not-null='true' type='java.lang.String' />
<property column='iso_cc2' length='2' name='isoCc2' not-null='true' type='java.lang.String' />
<property column='schedule_c' length='5' name='scheduleC' not-null='true' type='java.lang.String' />
<property column='region' length='20' name='region' not-null='true' type='java.lang.String' />
<property column='type' length='5' name='type' not-null='true' type='java.lang.String' />
<property column='who_modified' length='10' name='whoModified' not-null='true' type='java.lang.String' />
<property column='when_modified' length='14' name='whenModified' type='java.sql.Timestamp' />
<property column='lcl_region' length='30' name='lclRegion' not-null='true' type='java.lang.String' />
<property column='lcl_seq' length='11' name='lclSeq' not-null='true' type='int' />
<property column='iata_code' length='3' name='iataCode' not-null='true' type='java.lang.String' />
<!-- associations -->
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
in Loc.java:
public List query(final String portCode) throws Exception { // add type later
s=sessionFactory().openSession();
tx=s.beginTransaction();
Query locationByPortCode=s.createQuery("from Location l where l.portCode=:portCode");
locationByPortCode.setString("portCode",portCode);
//setParameter("foo", foo, Hibernate.INTEGER);
locationByPortCode.setCacheable(true);
//locationByPortCode.setCacheRegion("UserQueries");
final List l=locationByPortCode.list();
tx.commit();
s.close();
return l;
}
in LocTestCase.java:
public void testQuery() throws Exception {
info("log4jInfo");
TestCaseABC.log4jInfo();
info("is log4j Configured");
dsl.dao.DaoBC.isConfigured(null);
final String[] logger= {
"net.sf.hibernate.SQL",
"net.sf.hibernate.cache.ReadOnlyCache",
"net.sf.hibernate.cache.UpdateTimestampsCache",
"net.sf.hibernate.cache.QueryCache",
"net.sf.hibernate.cache.CacheFactory"
};
info("configuration properties: "+loc1.configuration.getProperties());
final Level oldLevel=Loc.logger.getLevel();
Loc.logger.setLevel(Level.ALL);
for(int i=0;i<logger.length;i++)
Logger.getLogger(logger[i]).setLevel(Level.DEBUG);
final String portCode="LAX";
info("portCode="+portCode);
for(int i=0;i<3;i++) {
final List found=loc1.query(portCode);
assertNotNull(found);
assertTrue(found.size()==1);
final Location l=(Location)found.get(0);
assertNotNull(l);
info("l is: "+l);
}
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
mysql version 12.22, dist 4.0.18 on win98/se
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
01:10:54,800 INFO Loc:71 - configure and build session factory
01:10:54,960 INFO Environment:462 - Hibernate 2.1.3
01:10:55,020 INFO Environment:496 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, hibernate.connection.url=jdbc:mysql://tayek.com:3306/test, hibernate.connection.password=, hibernate.connection.pool_size=1}
01:10:55,020 INFO Environment:518 - using java.io streams to persist binary types
01:10:55,020 INFO Environment:519 - using CGLIB reflection optimizer
01:10:55,070 INFO Configuration:347 - Mapping resource: loc/hibernate/Location.hbm.xml
01:10:55,840 INFO Binder:229 - Mapping class: loc.hibernate.Location -> location
01:10:56,230 INFO Loc:75 - url=jdbc:mysql://tayek.com/loc
01:10:56,230 INFO Configuration:613 - processing one-to-many association mappings
01:10:56,230 INFO Configuration:622 - processing one-to-one association property references
01:10:56,230 INFO Configuration:647 - processing foreign key constraints
01:10:56,340 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.MySQLDialect
01:10:56,340 INFO SettingsFactory:58 - Maximim outer join fetch depth: 1
01:10:56,340 INFO SettingsFactory:62 - Use outer join fetching: false
01:10:56,390 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)
01:10:56,390 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 1
01:10:56,390 INFO DriverManagerConnectionProvider:77 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://tayek.com/loc
01:10:56,390 INFO DriverManagerConnectionProvider:78 - connection properties: {user=root, password=}
01:10:56,450 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
01:10:56,830 INFO SettingsFactory:102 - Use scrollable result sets: true
01:10:56,830 INFO SettingsFactory:105 - Use JDBC3 getGeneratedKeys(): true
01:10:56,830 INFO SettingsFactory:108 - Optimize cache for minimal puts: false
01:10:56,830 INFO SettingsFactory:117 - Query language substitutions: {no='N', true=1, yes='Y', false=0}
01:10:56,830 INFO SettingsFactory:128 - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
01:10:56,830 INFO Configuration:1093 - instantiating and configuring caches
01:10:57,320 INFO SessionFactoryImpl:119 - building session factory
01:10:58,530 INFO SessionFactoryObjectFactory:82 - no JNDI name configured
01:10:58,530 INFO UpdateTimestampsCache:35 - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
01:10:58,590 INFO QueryCache:39 - starting query cache at region: net.sf.hibernate.cache.QueryCache
01:10:58,590 INFO Loc:82 - configured and built session factory
.01:10:58,700 INFO LocTestCase:258 - testQuery
01:10:58,700 INFO LocTestCase:258 - log4jInfo
[dsl., net.sf.hibernate.cache.ReadOnlyCache, domain.PODB, net.sf.hibernate.persister.AbstractEntityPersister, net.sf.hibernate.engine.Cascades, net.sf.hibernate.id.SequenceHiLoGenerator, tst.TestCaseABC, net.sf.hibernate.xml.XMLDatabinder, net.sf.hibernate.connection.DriverManagerConnectionProvider, net.sf.hibernate.impl.SessionFactoryObjectFactory, net.sf.hibernate.cfg.Mappings, net.sf.hibernate.persister.EntityPersister, dsl.Dao, dsl.DB, dsl.db.DB, net.sf.hibernate.id.TableGenerator, net.sf.hibernate.dialect.Dialect, net.sf.hibernate.util.ReflectHelper, net.sf.hibernate.connection.ConnectionProviderFactory, dsl.hibernate.HABC, net.sf.hibernate.cache.UpdateTimestampsCache, net.sf.hibernate.type, net.sf.hibernate.transaction.TransactionManagerLookupFactory, net.sf.hibernate.cfg.SettingsFactory, net.sf.hibernate.id.IncrementGenerator, net.sf.hibernate.cfg.Binder, net.sf.hibernate.cfg.Environment, dsl.hibernate.Loc, net.sf.hibernate.cache.CacheFactory, net.sf.hibernate.util.DTDEntityResolver, net.sf.hibernate.impl.SessionFactoryImpl, net.sf.hibernate.transaction.TransactionFactoryFactory, net.sf.hibernate.loader.Loader, net.sf.hibernate.id.TableHiLoGenerator, net.sf.hibernate.cfg.Configuration, net.sf.hibernate.property.BasicPropertyAccessor, dsl.hibernate.CASF, hex.Hex, net.sf.hibernate.cache.QueryCache, Main, net.sf.hibernate.id.SequenceGenerator, net.sf.hibernate.util.XMLHelper, dsl.hibernate.LocTestCase]
01:10:58,700 INFO LocTestCase:258 - is log4j Configured
package org.apache.log4j
Implementation title: log4j
Implementation vendor: "Apache Software Foundation"
Implementation version: 1.2.7
isConfigured()=true
01:10:58,810 INFO LocTestCase:258 - configuration properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, sun.boot.library.path=C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\bin, java.vm.version=1.4.1_01-b01, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, hibernate.cache.use_query_cache=true, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=US, sun.os.patch.level= A , java.vm.specification.name=Java Virtual Machine Specification, user.dir=H:\java\projects\hib, java.runtime.version=1.4.1_01-b01, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\WINDOWS\TEMP\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows 98, sun.java2d.fontpath=, java.library.path=C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\BIN;.;C:\WINDOWS\SYSTEM;C:\WINDOWS;C:\PROGRA~1\SYMANTEC\PCANYW~1\;D:\JAVA\JWSDP-1.3\JWSDP-SHARED\BIN;C:\WINDOWS;C:\WINDOWS\COMMAND;D:\BIN;C:\PROGRA~1\WIN98RK, java.specification.name=Java Platform API Specification, java.class.version=48.0, hibernate.connection.pool_size=1, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=4.10, user.home=C:\WINDOWS, user.timezone=America/Los_Angeles, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.4, hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, java.class.path=H:\java\projects\hib\bin;C:\Program Files\eclipse\plugins\org.junit_3.8.1\junit.jar;H:\java\projects\mylib\myutil.jar;H:\java\projects\hiblib\odmg-3.0.jar;H:\java\projects\hiblib\commons-collections-2.1.jar;H:\java\projects\hiblib\commons-lang.jar;H:\java\projects\hiblib\commons-logging.jar;H:\java\projects\hiblib\dbunit-2.1.jar;H:\java\projects\hiblib\diasparsoftToolkit-0.22.jar;H:\java\projects\hiblib\dom4j-1.4.jar;H:\java\projects\hiblib\hibernate2.jar;H:\java\projects\hiblib\hibernate-tools.jar;H:\java\projects\hiblib\jta.jar;H:\java\projects\hiblib\log4j.jar;H:\java\projects\hiblib\log4unit-0.2.0.jar;H:\java\projects\hiblib\mysql.jar;H:\java\projects\hiblib\cglib-2.0-rc2.jar, user.name=ray, hibernate.show_sql=false, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', java.vm.specification.version=1.0, java.home=C:\PROGRAM FILES\JAVA\J2RE1.4.1_01, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://tayek.com/loc, user.language=en, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, hibernate.jdbc.use_streams_for_binary=true, java.version=1.4.1_01, java.ext.dirs=C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\lib\ext, sun.boot.class.path=C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\lib\rt.jar;C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\lib\i18n.jar;C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\lib\sunrsasign.jar;C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\lib\jsse.jar;C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\lib\jce.jar;C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\lib\charsets.jar;C:\PROGRAM FILES\JAVA\J2RE1.4.1_01\classes, java.vendor=Sun Microsystems Inc., hibernate.jdbc.batch_size=0, file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, hibernate.max_fetch_depth=1, sun.cpu.isalist=pentium i486 i386}
01:10:58,860 INFO LocTestCase:258 - portCode=LAX
01:10:59,580 DEBUG QueryCache:61 - checking cached query results in region: net.sf.hibernate.cache.QueryCache
01:10:59,580 DEBUG QueryCache:64 - query results were not found in cache
01:10:59,580 DEBUG SQL:237 - select location0_.db_id as db_id, location0_.port_code as port_code, location0_.port_name as port_name, location0_.state_province as state_pr4_, location0_.country as country, location0_.iso_cc2 as iso_cc2, location0_.schedule_c as schedule_c, location0_.region as region, location0_.type as type, location0_.who_modified as who_mod10_, location0_.when_modified as when_mo11_, location0_.lcl_region as lcl_region, location0_.lcl_seq as lcl_seq, location0_.iata_code as iata_code from location location0_ where (location0_.port_code=? )
01:10:59,740 DEBUG ReadOnlyCache:44 - Caching: 78295
01:10:59,740 DEBUG QueryCache:46 - caching query results in region: net.sf.hibernate.cache.QueryCache
01:10:59,850 INFO LocTestCase:258 - l is: loc.hibernate.Location@acb158[dbId=78295]
01:10:59,850 DEBUG QueryCache:61 - checking cached query results in region: net.sf.hibernate.cache.QueryCache
01:10:59,850 DEBUG QueryCache:64 - query results were not found in cache
01:10:59,850 DEBUG SQL:237 - select location0_.db_id as db_id, location0_.port_code as port_code, location0_.port_name as port_name, location0_.state_province as state_pr4_, location0_.country as country, location0_.iso_cc2 as iso_cc2, location0_.schedule_c as schedule_c, location0_.region as region, location0_.type as type, location0_.who_modified as who_mod10_, location0_.when_modified as when_mo11_, location0_.lcl_region as lcl_region, location0_.lcl_seq as lcl_seq, location0_.iata_code as iata_code from location location0_ where (location0_.port_code=? )
01:10:59,910 DEBUG ReadOnlyCache:44 - Caching: 78295
01:10:59,910 DEBUG QueryCache:46 - caching query results in region: net.sf.hibernate.cache.QueryCache
01:10:59,910 INFO LocTestCase:258 - l is: loc.hibernate.Location@f9c40[dbId=78295]
01:10:59,910 DEBUG QueryCache:61 - checking cached query results in region: net.sf.hibernate.cache.QueryCache
01:10:59,910 DEBUG QueryCache:64 - query results were not found in cache
01:10:59,910 DEBUG SQL:237 - select location0_.db_id as db_id, location0_.port_code as port_code, location0_.port_name as port_name, location0_.state_province as state_pr4_, location0_.country as country, location0_.iso_cc2 as iso_cc2, location0_.schedule_c as schedule_c, location0_.region as region, location0_.type as type, location0_.who_modified as who_mod10_, location0_.when_modified as when_mo11_, location0_.lcl_region as lcl_region, location0_.lcl_seq as lcl_seq, location0_.iata_code as iata_code from location location0_ where (location0_.port_code=? )
01:10:59,910 DEBUG ReadOnlyCache:44 - Caching: 78295
01:10:59,910 DEBUG QueryCache:46 - caching query results in region: net.sf.hibernate.cache.QueryCache
01:10:59,910 INFO LocTestCase:258 - l is: loc.hibernate.Location@16f25a7[dbId=78295]
Time: 1.21
OK (1 test)