Background: Our project team is using Hibernate's dom4j entity mode to generate SOAP responses for a multiple client applications. The amount of data being delivered is massive and response time is an issue. We can significantly reduce the number of SQL calls by using the Hibernate Query Cache and/or the 2nd Level Cache. Due to the architecture of our system, the 1st Level Cache (Session) level mechanism will not improve performance in the way that Query Cacheing at the SessionFactory works.
Question: The underlying question is whether Hibernate's DOM4J Entity mode is compatible with Query cacheing. Query results are being put into the Query Cache. However, when a query.list()
method executes and a matching cached query is found, then the following exception is thrown:
Caused by:
java.lang.ClassCastException: org.dom4j.tree.DefaultElement cannot be cast to java.math.BigDecimal
at org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor.extractHashCode(BigDecimalTypeDescriptor.java:36)
at org.hibernate.type.AbstractStandardBasicType.getHashCode(AbstractStandardBasicType.java:197)
at org.hibernate.type.AbstractStandardBasicType.getHashCode(AbstractStandardBasicType.java:192)
at org.hibernate.engine.EntityKey.generateHashCode(EntityKey.java:126)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:70)
at org.hibernate.type.ManyToOneType.scheduleBatchLoadIfNeeded(ManyToOneType.java:160)
at org.hibernate.type.ManyToOneType.beforeAssemble(ManyToOneType.java:246)
at org.hibernate.cache.StandardQueryCache.get(StandardQueryCache.java:143)
at org.hibernate.loader.Loader.getResultFromQueryCache(Loader.java:2361)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2309)
at org.hibernate.loader.Loader.list(Loader.java:2268)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
Our environment is Core-Spring/Hibernate...
In our spring-hibernate session factory configuration, the following configuration is used:
<prop key= "hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
<prop key= "hibernate.cache.region.factory_class"> net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.query.factory_class"> org.hibernate.cache.StandardQueryCacheFactory</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cache.use_structured_entries">true</prop>
Initial Analysis: My gut feeling is that Hibernate's "experimental" DOM4J entity mode is not compatible with the Query and Entity Cache. It is also important to note that our Hibernate hbm.xml mapping files using dynamic mapping. That is, the mapping files do not have Class references; instead they have entity references. Thus, the XML responses get generated directly without populating a class's objects.
I would be tremendously grateful for any assistance in this matter.