Hi All,
New to the forum. I've been on a project rewriting a bioinformatics web site using Spring 3.0.5, Hibernate 3.3.2 and Ehcache 2.4.6. We are getting to a load testing stage and want to integrate ehcache. I think I have everything configured properly to get ehcache running. I see ehcache read its config and create the appropriate caches. I see debug messages as domain objects are hit telling me if it was a cache hit or miss is much worse then no 2nd level cache. All looks good, except...... When I watch the database log I still see the queries run, and the performance on what is supposedly the cache hit is horrible. At this point I am not sure where I an going wrong. I suspect a config/annotation problem, but darned if I can find it.
Oh, it may be important to mention a little of our architecture..... We have specialized Solr indexes for user queries. These return object keys which then get instantiated via session.get(Marker.class, id). We are happy with the performance. So adding ehcache is frosting. But I have little time left to figure out why it is making the performance worse, and still hitting the db.
On to some of the config.... I would greatly appreciate if someone could take a look and point out any error.
Thanks in advance,
MArk
my appContext-hibernate.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- ===================== RESOURCE DEFINITIONS ===================== -->
<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
<!-- (in this case, JDBC-related settings for the dataSource definition below) -->
<context:property-placeholder location="classpath:../properties/fewi.properties" />
<!-- JNDI DataSource for JEE environments -->
<jee:jndi-lookup id="dataSource" jndi-name="${jndi.datasource}"/>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.generate_statistics">
${hibernate.generate_statistics}
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>foo.frontend.datamodel</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory"/>
<tx:annotation-driven/>
<!--
Activates various annotations to be detected in bean classes:
Spring's @Required and @Autowired, as well as JSR 250's @Resource.
-->
<context:annotation-config/>
</beans>
My ehcache.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<defaultCache eternal="true" maxElementsInMemory="10000" overflowToDisk="false" statistics="true"/>
<cache
name="foo.frontend.datamodel.Marker"
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="false"
statistics="true" />
</ehcache>
and a snippet from my Marker object.....
Code:
@Entity
@Table(name="marker")
@SecondaryTables (
{ @SecondaryTable (name="marker_counts", pkJoinColumns= {
@PrimaryKeyJoinColumn(name="marker_key", referencedColumnName="marker_key") } )
} )
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region="mgi.frontend.datamodel.Marker")
public class Marker {
private List<MarkerAlias> aliases;
private List<MarkerAlleleAssociation> alleleAssociations;
private List<BatchMarkerAllele> batchMarkerAlleles;
............................ truncated for brevity........
// ================= Instance Methods ===================== //
/** used to make other convenience methods to extract only a certain types
* of annotations from the full List of annotations
*/
/**
* Returns a collection of marker annotation objects, which
* extend the base annotation class.
*/
@OneToMany
@JoinTable (name="marker_to_annotation",
joinColumns=@JoinColumn(name="marker_key"),
inverseJoinColumns=@JoinColumn(name="annotation_key")
)
@OrderBy("dagName, term")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public List<Annotation> getAnnotations() {
return annotations;
}