• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Caching with Spring + Hibernate JPA + JBoss Cache

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't seem to make the cache work properly

Here's my persistence.xml





application-context.xml






Test class




When running the test, I see in the console the SQL statement executed twice, although I would have expected that the object was already cached.
Thank you
 
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to specify which entities need to be cached along with the caching strategy. You can use Hibernate @Cache annotation. I am not sure if there is a equivalent for @Cache in JPA.

http://community.jboss.org/wiki/ClusteredJPAHibernateSecondLevelCachingInJBossAS5
 
c caseta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have already declared the objects as cacheable:



@Cacheable is a JPA annotation:
javax.persistence.Cacheable
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I noticed you have most of your JPA properties set in the persistence.xml instead of the Spring configuration for your org.springframework.orm.jpa.LocalEntityManagerFactoryBean. So why the LocalEntityManagerFactoryBean and not org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean?

Not a big deal, just that you can have a very simple persistence.xml file with just the persistence name. Also the LocalContainer version give your more control. Check out the Spring docs on it.

Thanks

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic