java—jpa中的二级缓存,对本机查询和jpql使用实体管理器

0g0grzrc  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(250)

我已经通过entitymanager使用jpa实现了二级缓存,并对其使用java配置。我引用了以下链接http://www.baeldung.com/hibernate-second-level-cache. 我没有得到任何错误,但我的实体的数据也没有缓存。请帮忙:)
我已经提供了在应用程序中启用二级缓存所需的所有配置,下面是我的conf代码iguration:-
这是我的application.properties文件-

spring.jpa.properties.javax.persistence.sharedCache.mode = ENABLE_SELECTIVE
spring.jpa.properties.hibernate.cache.use_query_cache = true
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.provider_class = net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
spring.jpa.properties.hibernate.jdbc.batch_size=10

这是我的实体类-

@Entity
@Cacheable(true)
@org.hibernate.annotations.Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "booking")

这是我在应用程序的控制台日志中得到的信息,即每次我处理同一个请求时,查询都会在每个请求中处理数据库。这就是二级缓存不涉及的原因。

Hibernate: SELECT booking.BId,booking.calledDate Called, booking.calleduser Caller, booking.callerNotes, booking.Title, booking.FName, booking.ScName, booking.bookingPhase, Training.TName, booking.TrDate, booking.SubmitDateTime, trlocation.TrLocation trTrl, booking.STATUS, booking.DelegNum, booking.Tel, booking.Email,booking.Notes FROM(SELECT booking.* FROM booking booking WHERE booking.SubmitDateTime > DATE_SUB(NOW(), INTERVAL 2 MONTH) AND booking.SId > 0 ORDER BY booking.BId DESC LIMIT 1) booking LEFT JOIN training Training ON booking.Training = Training.TId LEFT JOIN confirmation ON booking.Bid = confirmation.Bid LEFT JOIN trlocation ON booking.TrLocation = trlocation.TrLId LEFT JOIN invoice ON booking.BId =invoice.BId AND invoice.PayReceiveBy='' AND invoice.Id='-1' LEFT JOIN couriertracking ON booking.BId = couriertracking.bId LEFT JOIN salesperson ON booking.SId = salesperson.SId AND booking.SId > 0 
----------the data is NOT cached
Hibernate: SELECT booking.BId,booking.calledDate Called, booking.calleduser Caller, booking.callerNotes, booking.Title, booking.FName, booking.ScName, booking.bookingPhase, Training.TName, booking.TrDate, booking.SubmitDateTime, trlocation.TrLocation trTrl, booking.STATUS, booking.DelegNum, booking.Tel, booking.Email,booking.Notes FROM(SELECT booking.* FROM booking booking WHERE booking.SubmitDateTime > DATE_SUB(NOW(), INTERVAL 2 MONTH) AND booking.SId > 0 ORDER BY booking.BId DESC LIMIT 1) booking LEFT JOIN training Training ON booking.Training = Training.TId LEFT JOIN confirmation ON booking.Bid = confirmation.Bid LEFT JOIN trlocation ON booking.TrLocation = trlocation.TrLId LEFT JOIN invoice ON booking.BId =invoice.BId AND invoice.PayReceiveBy='' AND invoice.Id='-1' LEFT JOIN couriertracking ON booking.BId = couriertracking.bId LEFT JOIN salesperson ON booking.SId = salesperson.SId AND booking.SId > 0 
----------the data is NOT cached

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题