I have an entity mapped from a database view. It has a primary key field as well.
@Entity(name = "VAwaitedDocs")
@Table(schema = "OPS_TRACKING", name = "V_AWAITED_DOCS")
@Cache(usage= org.hibernate.annotations.CacheConcurrencyStrategy.READ_ONLY)
@NamedQuery(name="findAll",
query="select v from VAwaitedDocs v",
hints={@QueryHint(name="org.hibernate.cachemode", value="GET"), @QueryHint(name="org.hibernate.cacheable", value="true"), @QueryHint(name="org.hibernate.cacheRegion", value="opstraing.model.VAwaitedDocs")})
public class VAwaitedDocs implements Serializable {
.
.
. @Id
@Column(name = "TRADE_RQMT_ID", nullable = false, length = 12)
public Long getTradeRqmtId() {
return tradeRqmtId;
}
In my persistence file, i am using jboss cache.
<property name="hibernate.cache.provider_class" value="org.jboss.ejb3.entity.TreeCacheProviderHook"/>
<property name="hibernate.treecache.mbean.object_name" value="jboss.cache:service=EJB3EntityTreeCache"/>
I have a dao class that has a method findAll().
public List<T> findAll() {
return getEntityManager().createQuery("from " + getEntityBeanType().getName() ).getResultList();
}
I then have a test unit that does the following:
for (int i = 0; i <= 5; i++) {
TestTimer timer = new TestTimer("Find All");
awaitedDocs = bean.findAll();
timer.done();
System.out.println("Total Found: " + awaitedDocs.size());
awaitedDocs.clear(); }
after the initial findAll()..... I can see that the cache is populated with the correct data. I see this using the jmx-console and the printDetails method.
But, the performance is exactly the same. I think it is NOT getting the data from the cache, but making another DB call to get the list. There are about 15,000 rows returned. The Initial call takes about 19 seconds, and the rest of the calls take the same amount of time. does this call keep making DB calls, or does it use the cache? Thanks in advance.
|