File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Caching with Spring + Hibernate JPA + JBoss Cache

 
c caseta
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already declared the objects as cacheable:



@Cacheable is a JPA annotation:
javax.persistence.Cacheable
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic