Hello!
I have the following problem with second-level and query caches. Plainly speaking, nothing gets put in them.
Inside a Hibernate transaction, I persist some new entities. To persist them, I need to gather some data first, so I load some other entities, which are already persisted from previous transactions within the same session. This is where the problem starts.
I use a Criteria query to gather the necessary information, using following code:
Code:
Criteria crit = this.getSession().createCriteria(MachineEntity.class);
crit.setCacheMode(CacheMode.NORMAL);
crit.setCacheable(true);
crit.add(Restrictions.idEq(10));
return (MachineEntity)crit.uniqueResult();
Having both second-level cache and query cache enabled, I'd expect that the query would get cached, as well as the resulting entity. However, neither of those two happens. (As verified by echoing hit/miss statistics.) The following query is executed every time I run the aforementioned code, although it should in my opinion run only once:
Code:
select this_.id as id2_0_, this_.CPUs as CPUs2_0_, this_.HDD as HDD2_0_, this_.OS as OS2_0_, this_.RAM as RAM2_0_, this_.name as name2_0_, this_.platform as platform2_0_, this_.speed as speed2_0_ from MachineEntity this_ where this_.name=?
Any ideas as to why this would happen? Following is my hibernate.cfg.xml as well as the log of Hibernate.
Code:
<hibernate-configuration>
<session-factory>
<!-- DB connection -->
<property name="hibernate.connection.driver_class">SQLite.JDBCDriver</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLiteDialect</property>
<!-- Some SQL-related stuff -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Caching -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.cache.use_query_cache">true</property>
<!-- Specify mapped entities -->
<mapping class="cz.muni.fi.spc.SchedVis.model.entities.Event" />
<mapping class="cz.muni.fi.spc.SchedVis.model.entities.EventType" />
<mapping class="cz.muni.fi.spc.SchedVis.model.entities.MachineEntity" />
<mapping class="cz.muni.fi.spc.SchedVis.model.entities.GroupEntity" />
</session-factory>
</hibernate-configuration>
Code:
INFO Version - Hibernate Annotations 3.4.0.GA
INFO Environment - Hibernate 3.3.0.SP1
INFO Environment - hibernate.properties not found
INFO Environment - Bytecode provider name : javassist
INFO Environment - using JDK 1.4 java.sql.Timestamp handling
INFO Version - Hibernate Commons Annotations 3.1.0.GA
INFO Configuration - configuring from resource: /hibernate.cfg.xml
INFO Configuration - Configuration resource: /hibernate.cfg.xml
INFO Configuration - Configured SessionFactory: null
INFO HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
INFO AnnotationBinder - Binding entity from annotated class: cz.muni.fi.spc.SchedVis.model.entities.Event
INFO EntityBinder - Bind entity cz.muni.fi.spc.SchedVis.model.entities.Event on table Event
INFO AnnotationBinder - Binding entity from annotated class: cz.muni.fi.spc.SchedVis.model.entities.EventType
INFO EntityBinder - Bind entity cz.muni.fi.spc.SchedVis.model.entities.EventType on table EventType
INFO AnnotationBinder - Binding entity from annotated class: cz.muni.fi.spc.SchedVis.model.entities.MachineEntity
INFO EntityBinder - Bind entity cz.muni.fi.spc.SchedVis.model.entities.MachineEntity on table MachineEntity
INFO AnnotationBinder - Binding entity from annotated class: cz.muni.fi.spc.SchedVis.model.entities.GroupEntity
INFO EntityBinder - Bind entity cz.muni.fi.spc.SchedVis.model.entities.GroupEntity on table GroupEntity
INFO Version - Hibernate Validator 3.1.0.GA
INFO DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
INFO DriverManagerConnectionProvider - Hibernate connection pool size: 20
INFO DriverManagerConnectionProvider - autocommit mode: false
INFO DriverManagerConnectionProvider - using driver: SQLite.JDBCDriver at URL: jdbc:sqlite:/asddfatsertsert.sqlite
INFO DriverManagerConnectionProvider - connection properties: {}
INFO SettingsFactory - RDBMS: SQLite, version: 3.5.9
INFO SettingsFactory - JDBC driver: SQLite/JDBC, version: 1.20081006
INFO Dialect - Using dialect: org.hibernate.dialect.SQLiteDialect
INFO TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
INFO TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO SettingsFactory - Automatic flush during beforeCompletion(): disabled
INFO SettingsFactory - Automatic session close at end of transaction: disabled
INFO SettingsFactory - Scrollable result sets: enabled
INFO SettingsFactory - JDBC3 getGeneratedKeys(): disabled
INFO SettingsFactory - Connection release mode: auto
INFO SettingsFactory - Default batch fetch size: 1
INFO SettingsFactory - Generate SQL with comments: disabled
INFO SettingsFactory - Order SQL updates by primary key: disabled
INFO SettingsFactory - Order SQL inserts for batching: disabled
INFO SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
INFO SettingsFactory - Query language substitutions: {}
INFO SettingsFactory - JPA-QL strict compliance: disabled
INFO SettingsFactory - Second-level cache: enabled
INFO SettingsFactory - Query cache: enabled
INFO SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
INFO RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.HashtableCacheProvider
INFO SettingsFactory - Optimize cache for minimal puts: disabled
INFO SettingsFactory - Structured second-level cache entries: disabled
INFO SettingsFactory - Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
INFO SettingsFactory - Echoing all SQL to stdout
INFO SettingsFactory - Statistics: disabled
INFO SettingsFactory - Deleted entity synthetic identifier rollback: disabled
INFO SettingsFactory - Default entity-mode: pojo
INFO SettingsFactory - Named query checking : enabled
INFO SessionFactoryImpl - building session factory
INFO SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
INFO SchemaUpdate - Running hbm2ddl schema update
INFO SchemaUpdate - fetching database metadata
INFO SchemaUpdate - updating schema
INFO DatabaseMetadata - table not found: Event
INFO DatabaseMetadata - table not found: EventType
INFO DatabaseMetadata - table not found: Event_Event
INFO DatabaseMetadata - table not found: GroupEntity
INFO DatabaseMetadata - table not found: GroupEntity_MachineEntity
INFO DatabaseMetadata - table not found: MachineEntity
INFO DatabaseMetadata - table not found: Event
INFO DatabaseMetadata - table not found: EventType
INFO DatabaseMetadata - table not found: Event_Event
INFO DatabaseMetadata - table not found: GroupEntity
INFO DatabaseMetadata - table not found: GroupEntity_MachineEntity
INFO DatabaseMetadata - table not found: MachineEntity
INFO SchemaUpdate - schema update complete
INFO UpdateTimestampsCache - starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
INFO StandardQueryCache - starting query cache at region: org.hibernate.cache.StandardQueryCache
I should perhaps add that I use SQLite 3.x (javasqlite JDBC driver, own dialect) on Linux.