Results 1 to 2 of 2

Thread: @Cacheable on entity findAll causes hibernate exception

  1. #1
    Join Date
    Apr 2006
    Posts
    21

    Default @Cacheable on entity findAll causes hibernate exception

    I used Roo to build a JPA/Hibernate application and I now want to make use of Spring's Cache abstraction that came out in 3.1.

    when I add @Cacheable(value = "subjects") like so to the Roo generated method (after pushing the method into the main class:

    Code:
    	@Cacheable(value="subjects")
    	public static List<Subject> findAllSubjects() {
            return entityManager().createQuery("SELECT o FROM Subject o", Subject.class).getResultList();
        }
    I get the follow error:

    Code:
    Data access failure
    
    Sorry, a problem occurred while accessing the database.
    
    Details
    org.hibernate.InstantiationException: Could not instantiate entity: edu.wisc.acadprop.domain.Subject; nested exception is javax.persistence.PersistenceException: org.hibernate.InstantiationException: Could not instantiate entity: edu.wisc.acadprop.domain.Subject
    org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:326)
    org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$18a1ac9(JpaExceptionTranslatorAspect.aj:15)
    Here are my relevant configurations:

    ehcache.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?> 
    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"> 
    	<defaultCache maxElementsInMemory="1000" eternal="false" overflowToDisk="true" memoryStoreEvictionPolicy="LFU" />
    	<cache name="subjects" maxElementsInMemory="500" eternal="false" overflowToDisk="false"
    		memoryStoreEvictionPolicy="LFU" />
    </ehcache>
    applicationContext.xml
    Code:
        <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        	<property name="cacheManager" ref="ehcache"></property>
        </bean>
    
    	<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    		<property name="configLocation" value="classpath:ehcache.xml"></property>
    	</bean>
    If I comment out @Cacheable, things work fine.

    What am I missing?

  2. #2
    Join Date
    Jun 2010
    Posts
    440

    Default

    @lili5058,

    Yours is a List collection coming from a JPA datasource...
    JPA spec has its way for doing caching. I recall someone publishing in this forum the configuration for enabling using JPA-hibernate.
    Dig a litter more and you will find it.

    I hope this helps you
    jD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •