Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

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: 17346
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
 
It will give me the powers of the gods. Not bad for a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic