aspose file tools*
The moose likes Spring and the fly likes Caching with Spring + Hibernate JPA + JBoss Cache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Caching with Spring + Hibernate JPA + JBoss Cache" Watch "Caching with Spring + Hibernate JPA + JBoss Cache" New topic
Author

Caching with Spring + Hibernate JPA + JBoss Cache

c caseta
Greenhorn

Joined: Aug 11, 2011
Posts: 2
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

Joined: Aug 11, 2010
Posts: 218

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

Joined: Aug 11, 2011
Posts: 2
I have already declared the objects as cacheable:



@Cacheable is a JPA annotation:
javax.persistence.Cacheable
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Caching with Spring + Hibernate JPA + JBoss Cache