Test Case for defining JPA caching
When selective caching and second level cache is enabled through the JPA persistence.xml configuration file, entites that are defined in orm.xml with cacheable="true" attribute are not cached in the second level cache.
Entities that are annotated @Cacheable(true) are cached correctly
This test case test the following 4 scenarios
Entity is annotated with @Cacheable(true) Entity is defined as cacheable in orm.xml Entity is defined as cacheable with hibernate.ejb.classcache in persistence.xml Entity has not been defined as cacheable and therefore should not be cached
Methodology For each test
A new customer is created and persisted through JPA. A JDBC call is made to update CUST_CREDIT value directly to database by picking a connection from connection pool and executing a SQL statement The customer entity is retrieved through JPA by finding on PK The customer availableCredit property of the retrieved object is compared to the CUST_CREDIT value set in step 2 If availableCredit==CUST_CREDIT, the entity has not been cached. if availableCredit!=CUST_CREDIT, the entity has not been cached.
Expected Results
a) Annotated Entity cached==true b) XML Entity cached==true c) Hibernate defined Entity cached==true d) Not cached Entity cached==false
|