spring boot集成ehcache 2.x 用于hibernate二级缓存

深入解析Ehcache:Java本地缓存核心架构、Spring Boot集成与生产实践 缓存是提升应用性能、降低数据库负载的关键技术,其核心原理是在内存等高速介质中暂存计算结果,以空间换时间。本地缓存作为缓存体系的重要一环,直接嵌入应用进程,避免了网络开销,能提供纳秒级的访问速度,尤其适合高并发读场景。Ehcache作为Java生态中成熟且功能完备的本地缓存框架,其技术价值在于通过精巧的三层存储模型(堆内、堆外、磁盘),在访问速度、缓存容量与垃圾回收(GC)压力间实现了高效平衡。它支持多种缓存淘汰策略(如LRU、LFU)和细粒度的数据过期控制(TTL/TTI),并能与Spring Cache抽 阅读详情

spring boot集成ehcache 2.x 用于hibernate二级缓存

本文将介绍如何在spring boot中集成ehcache作为hibernate的二级缓存。各个框架版本如下

  • spring boot:1.4.3.RELEASE
  • spring framework: 4.3.5.RELEASE
  • hibernate:5.0.1.Final(spring-boot-starter-data-jpa默认依赖)
  • ehcache:2.10.3

项目依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-ehcache</artifactId>
    <exclusions>
        <exclusion>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>2.10.3</version>
</dependency>   

Ehcache简介

ehcache是一个纯java的缓存框架,既可以当做一个通用缓存使用,也可以作为将其作为hibernate的二级缓存使用。缓存数据可选择如下三种存储方案

  • MemoryStore – On-heap memory used to hold cache elements. This tier is subject to Java garbage collection.

  • OffHeapStore – Provides overflow capacity to the MemoryStore. Limited in size only by available RAM. Not subject to Java garbage collection (GC). Available only with Terracotta BigMemory products.

  • DiskStore – Backs up in-memory cache elements and provides overflow capacity to the other tiers.

hibernate二级缓存配置

hibernate的二级缓存支持entity和query层面的缓存,org.hibernate.cache.spi.RegionFactory各类可插拔的缓存提供商与hibernate的集成。

# 打开hibernate统计信息
spring.jpa.properties.hibernate.generate_statistics=true

# 打开二级缓存
spring.jpa.properties.hibernate.cache.use_second_level_cache=true

# 打开查询缓存
spring.jpa.properties.hibernate.cache.use_query_cache=true

# 指定缓存provider
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory

# 配置shared-cache-mode
spring.jpa.properties.javax.persistence.sharedCache.mode=ENABLE_SELECTIVE

关于hibernate缓存相关的所有配置可参考hibernate5.0官方文档#缓存

ehcache配置文件

ehcache 2.x配置文件样板参考官方网站提供的ehcache.xml。本例中使用的配置文件如下所示

<?xml version="1.0" encoding="UTF-8"?>

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd"
     updateCheck="true" monitoring="autodetect"
     dynamicConfig="true">

    <diskStore path="user.dir/cache"/>
    <transactionManagerLookup class="net.sf.ehcache.transaction.manager.DefaultTransactionManagerLookup"
                              properties="jndiName=java:/TransactionManager" propertySeparator=";"/>
    <cacheManagerEventListenerFactory class="com.yangyi.base.ehcache.CustomerCacheManagerEventListenerFactory" properties=""/>

    <defaultCache
       maxEntriesLocalHeap="0"
       eternal="false"
       timeToIdleSeconds="1200"
       timeToLiveSeconds="1200">
      <!--<terracotta/>-->
    </defaultCache>

    <cache name="entityCache"
            maxEntriesLocalHeap="1000"
            maxEntriesLocalDisk="10000"
            eternal="false"
            diskSpoolBufferSizeMB="20"
            timeToIdleSeconds="10"
            timeToLiveSeconds="20"
            memoryStoreEvictionPolicy="LFU"
            transactionalMode="off">
        <persistence strategy="localTempSwap"/>
        <cacheEventListenerFactory class="com.yangyi.base.ehcache.CustomerCacheEventListenerFactory" />
    </cache>

    <cache name="org.hibernate.cache.internal.StandardQueryCache"
           maxEntriesLocalHeap="5" eternal="false" timeToLiveSeconds="120">
        <persistence strategy="localTempSwap" />
        <cacheEventListenerFactory class="com.yangyi.base.ehcache.CustomerCacheEventListenerFactory" />
    </cache>

    <cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
           maxEntriesLocalHeap="5000" eternal="true">
        <persistence strategy="localTempSwap" />
        <cacheEventListenerFactory class="com.yangyi.base.ehcache.CustomerCacheEventListenerFactory" />
    </cache>
</ehcache>

ehcache事件监听

在ehcache中,有两大类事件,一是cacheManager相关的事件,如cache的init/added等;二是cahche相关的事件,如cache put/expire等。在ehcache中,默认没有这两类事件的监听器,需要自主实现监听器以及监听器工厂类,然后配置到ehcache.xml中,方可生效。
上述ehcache.xml配置中,给自定义cache都配置了cacheEventListenerFactory,用于监听缓存事件。同时也配置了cacheManager Factory实现类。具体实现代码如下

CacheManagerEventListener简单实现

package com.yangyi.base.ehcache;

import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Status;
import net.sf.ehcache.event.CacheManagerEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * ehcache customer cacheManagerEventListener
 * Created by yangjinfeng on 2017/1/5.
 */
public class CustomerCacheManagerEventListener implements CacheManagerEventListener {

    private Logger logger = LoggerFactory.getLogger(getClass());

    private final CacheManager cacheManager;

    public CustomerCacheManagerEventListener(CacheManager cacheManager) {
        this.cacheManager = cacheManager;
    }

    @Override
    public void init() throws CacheException {
        logger.info("init ehcache...");
    }

    @Override
    public Status getStatus() {
        return null;
    }

    @Override
    public void dispose() throws CacheException {
        logger.info("ehcache dispose...");
    }

    @Override
    public void notifyCacheAdded(String s) {
        logger.info("cacheAdded... {}", s);
        logger.info(cacheManager.getCache(s).toString());
    }

    @Override
    public void notifyCacheRemoved(String s) {

    }
}

CacheManagerEventListenerFactory的简单实现

package com.yangyi.base.ehcache;

import net.sf.ehcache.CacheManager;
import net.sf.ehcache.event.CacheManagerEventListener;
import net.sf.ehcache.event.CacheManagerEventListenerFactory;

import java.util.Properties;

/**
 * Created by yangjinfeng on 2017/1/5.
 */
public class CustomerCacheManagerEventListenerFactory extends CacheManagerEventListenerFactory {
    @Override
    public CacheManagerEventListener createCacheManagerEventListener(CacheManager cacheManager, Properties properties) {
        return new CustomerCacheManagerEventListener(cacheManager);
    }
}

CacheEventListener的简单实现

package com.yangyi.base.ehcache;

import net.sf.ehcache.CacheException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.event.CacheEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by yangjinfeng on 2017/1/5.
 */
public class CustomerCacheEventListener implements CacheEventListener {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void notifyElementRemoved(Ehcache ehcache, Element element) throws CacheException {
        logger.info("cache removed. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
    }

    @Override
    public void notifyElementPut(Ehcache ehcache, Element element) throws CacheException {
        logger.info("cache put. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
    }

    @Override
    public void notifyElementUpdated(Ehcache ehcache, Element element) throws CacheException {
        logger.info("cache updated. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
    }

    @Override
    public void notifyElementExpired(Ehcache ehcache, Element element) {
        logger.info("cache expired. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
    }

    @Override
    public void notifyElementEvicted(Ehcache ehcache, Element element) {
        logger.info("cache evicted. key = {}, value = {}", element.getObjectKey(), element.getObjectValue());
    }

    @Override
    public void notifyRemoveAll(Ehcache ehcache) {
        logger.info("all elements removed. cache name = {}", ehcache.getName());
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException();
    }

    @Override
    public void dispose() {
        logger.info("cache dispose.");
    }
}

CacheEventListenerFactory的简单实现

package com.yangyi.base.ehcache;

import net.sf.ehcache.event.CacheEventListener;
import net.sf.ehcache.event.CacheEventListenerFactory;

import java.util.Properties;

/**
 * Created by yangjinfeng on 2017/1/5.
 */
public class CustomerCacheEventListenerFactory extends CacheEventListenerFactory {
    @Override
    public CacheEventListener createCacheEventListener(Properties properties) {
        return new CustomerCacheEventListener();
    }
}

完成上述事件监听器的实现和配置后,我们可以启动应用,查看下相应事件监听器中输出的log,以验证是否生效

2017-01-07 10:27:07.810  INFO 4264 --- [           main] com.yangyi.Application                   : Starting Application on yangjinfeng-pc with PID 4264 (E:\JavaWorkSpace\spring-boot-ehcache3-hibernate5-jcache\target\classes started by yangjinfeng in E:\JavaWorkSpace\spring-boot-ehcache3-hibernate5-jcache)
2017-01-07 10:27:07.810  INFO 4264 --- [           main] com.yangyi.Application                   : No active profile set, falling back to default profiles: default
2017-01-07 10:27:07.865  INFO 4264 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2ef3eef9: startup date [Sat Jan 07 10:27:07 CST 2017]; root of context hierarchy
2017-01-07 10:27:09.155  INFO 4264 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$6eb4eae9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.191  INFO 4264 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cache.annotation.ProxyCachingConfiguration' of type [class org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$b7c72107] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.206  INFO 4264 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration' of type [class org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration$$EnhancerBySpringCGLIB$$ac3ae5ab] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.285  INFO 4264 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.cache-org.springframework.boot.autoconfigure.cache.CacheProperties' of type [class org.springframework.boot.autoconfigure.cache.CacheProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.291  INFO 4264 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers' of type [class org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.293  INFO 4264 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.cache.EhCacheCacheConfiguration' of type [class org.springframework.boot.autoconfigure.cache.EhCacheCacheConfiguration$$EnhancerBySpringCGLIB$$46d9b2a9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.418  INFO 4264 --- [           main] .y.b.e.CustomerCacheManagerEventListener : init ehcache...
2017-01-07 10:27:09.487  INFO 4264 --- [           main] .y.b.e.CustomerCacheManagerEventListener : cacheAdded... org.hibernate.cache.spi.UpdateTimestampsCache
2017-01-07 10:27:09.487  INFO 4264 --- [           main] .y.b.e.CustomerCacheManagerEventListener : [ name = org.hibernate.cache.spi.UpdateTimestampsCache status = STATUS_ALIVE eternal = true overflowToDisk = true maxEntriesLocalHeap = 5000 maxEntriesLocalDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 0 timeToIdleSeconds = 0 persistence = LOCALTEMPSWAP diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: com.yangyi.base.ehcache.CustomerCacheEventListener ; orderedCacheEventListeners:  maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ]
2017-01-07 10:27:09.487  INFO 4264 --- [           main] .y.b.e.CustomerCacheManagerEventListener : cacheAdded... org.hibernate.cache.internal.StandardQueryCache
2017-01-07 10:27:09.487  INFO 4264 --- [           main] .y.b.e.CustomerCacheManagerEventListener : [ name = org.hibernate.cache.internal.StandardQueryCache status = STATUS_ALIVE eternal = false overflowToDisk = true maxEntriesLocalHeap = 5 maxEntriesLocalDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 120 timeToIdleSeconds = 0 persistence = LOCALTEMPSWAP diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: com.yangyi.base.ehcache.CustomerCacheEventListener ; orderedCacheEventListeners:  maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ]
2017-01-07 10:27:09.503  INFO 4264 --- [           main] .y.b.e.CustomerCacheManagerEventListener : cacheAdded... entityCache
2017-01-07 10:27:09.503  INFO 4264 --- [           main] .y.b.e.CustomerCacheManagerEventListener : [ name = entityCache status = STATUS_ALIVE eternal = false overflowToDisk = true maxEntriesLocalHeap = 1000 maxEntriesLocalDisk = 10000 memoryStoreEvictionPolicy = LFU timeToLiveSeconds = 20 timeToIdleSeconds = 10 persistence = LOCALTEMPSWAP diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: com.yangyi.base.ehcache.CustomerCacheEventListener ; orderedCacheEventListeners:  maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ]
2017-01-07 10:27:09.503  INFO 4264 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'ehCacheCacheManager' of type [class net.sf.ehcache.CacheManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.503  INFO 4264 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'cacheManager' of type [class org.springframework.cache.ehcache.EhCacheCacheManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.503  INFO 4264 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'cacheAutoConfigurationValidator' of type [class org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration$CacheManagerValidator] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-01-07 10:27:09.829  INFO 4264 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-01-07 10:27:09.839  INFO 4264 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-01-07 10:27:09.839  INFO 4264 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
2017-01-07 10:27:09.924  INFO 4264 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-01-07 10:27:09.924  INFO 4264 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2061 ms

2017-01-07 10:32:41.876  INFO 4264 --- [nio-8080-exec-1] c.y.b.e.CustomerCacheEventListener       : cache put. key = com.yangyi.entity.User#1, value = org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy$Item@1c13194d
2017-01-07 10:32:41.877  INFO 4264 --- [nio-8080-exec-1] c.y.b.e.CustomerCacheEventListener       : cache put. key = com.yangyi.entity.Authority#1, value = org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy$Item@2accc177
2017-01-07 10:32:41.878  INFO 4264 --- [nio-8080-exec-1] c.y.b.e.CustomerCacheEventListener       : cache put. key = com.yangyi.entity.Authority#2, value = org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy$Item@2b3b9c7e
2017-01-07 10:32:41.879  INFO 4264 --- [nio-8080-exec-1] c.y.b.e.CustomerCacheEventListener       : cache put. key = com.yangyi.entity.Authority#3, value = org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy$Item@4c31e58c

注解方式使用二级缓存

要使用entity cache,需要在entity上配上相应的注解方可生效。javax.persistence.Cacheable注解标记该entity使用二级缓存,org.hibernate.annotations.Cache注解指定缓存策略,以及存放到哪个缓存区域。
有关缓存策略详细信息可参考hibernate5.0官方文档#缓存

package com.yangyi.entity;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.JoinTable;

@Entity
@Table(name = "users")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "entityCache")
public class User implements Serializable {

}

最后,我们需要在spring boot应用层面打开cache功能,使用org.springframework.cache.annotation.EnableCaching注解

package com.yangyi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

@SpringBootApplication
@EnableCaching
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

完整代码

完整代码示例见github spring-boot-ehcache2.x-hibernate-second-level-cache

Spring与Hibernate集成开发实战指南 对象关系映射(ORM)是Java企业级开发中的核心技术,Hibernate作为主流ORM框架,通过将数据库表映射为Java对象,显著简化数据持久化操作。其核心原理包括会话管理、延迟加载和缓存机制,能有效降低开发者直接操作JDBC的复杂度。结合Spring框架的依赖注入和声明式事务管理,可以构建高可维护性的数据访问层,特别适合需要处理复杂对象关系的电商、ERP等系统。通过SessionFactory配置和@Transactional注解的合理使用,开发者能解决N+1查询等典型性能问题,而二级缓存集成则可提升高 阅读详情

相关推荐

Spring Boot 3与Hibernate 6的二级缓存配置详解

本文介绍了在Spring Boot 3中配置Hibernate 6与Ehcache 3实现二级缓存的方法。通过添加相关依赖、配置应用属性、启用缓存注解等步骤,详细说明了如何为实体类设置缓存并验证效果。文章提供了一个完整的EmailStatus缓存示例,展示如何通过查询方法和服务层实现缓存功能,最终通过日志验证缓存命中情况,有效减少数据库访问提升应用性能。

2501_90323865的博客 85

SpringBoot 2.0.4 使用Ehcache作为Hibernate的二级缓存和系统缓存

本文基于springboot 2.0.4 使用ehcache作为Hibernate的二级缓存 以及系统缓存 额外需要用的是mysql数据库 由于springboot2.x和1.x差别较大 使用1.x可能会有错误 另外ehcache版本也会导致有不同的问题 本文默认使用了spring-boot-starter-cache里面的ehcache 首先 先看一下POM文件的配置 &amp;amp;amp;lt;?xm...

yingziisme的博客 5111

springboot+jpa(hibernate配置redis为二级缓存) springboot2.1.4

基于springboot最新版本2.1.4.RELEASE,采用jpa为dao层框架,配置redis(redisson)为hibernate的二级缓存。

SpringBoot2.X正确配置以及集成hibernate5正确姿势

个人认为本人是目前SpringBoot2.X集成hibernate5最全的写法,大家有什么意见建议欢迎评论。 本人前面配置以及代码使用图片展示,方便圈出注意点,图片中的代码将在文章结尾一一放出。 1.springboot2.x的application.yml的配置文件 注意点在于2.*相较于1.*项目名访问设置不一样了。还有session时间的设置方法,具体的可以看我的注释。 2.applica...

wt592376761的博客 1万+

springboot2.x整合redis做mybatis的二级缓存

springboot整合redis做mybatis的二级缓存,含有自定义key,自定义过期时间,自定义序列化方式

为Spring集成的Hibernate配置二级缓存

为Spring集成的Hibernate配置二级缓存

Springboot为啥要有第二级缓存

在递归创建其他依赖的组件前,会将未完成的组件作为放入ObjectFactory类的一个实现类里面,生成他的代理对象objectProxy,然后把这个ObjectFactory对象放入到二级缓存里面,通过调用getEarlyBeanReference来获取未完成的bean,如果这个对象没有被aop动态代理,就直接返回原来的对象,如果被aop代理过,就为这个对象生成代理对象,然后返回的就是代理对象。,只要获取到它的地址,然后赋值过来就行了,所以它是在一级缓存还是在二级缓存并不重要。

qwqgood的博客 2113

详解spring boot集成ehcache 2.x 用于hibernate二级缓存

本篇文章主要介绍了详解spring boot集成ehcache 2.x 用于hibernate二级缓存,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

hibernate在springboot中简单使用

hibernate在springboot中简单使用 文章目录hibernate在springboot中简单使用1.前言2.springboot中整合hibernate2.1导入hibernate依赖和连接数据库依赖2.3配置实体类(我全用的注解方式)2.4创建一个接口操作hibernate自带的方法2.5controller类 1.前言 我这里整理出的是不涉及多表查询等复杂的sql实现,只为hibernate简单上手使用 一般用了hibernate的人都多多少少接触了mybatis,这里我简单说一哈我对这两

weixin_41657954的博客 9233

一文搞定3D卷积

在讨论卷积核的时候,是不把channel维加进去的 核 = 一个可以滑动的窗口 窗口内不同位置数据之间的权值共享 3D卷积,卷积核会在3个方向上运动,那么卷积核的运动需要有三个自由度(一小块立方体,在一个大面包块内3个方向上滑动 2D卷积,卷积核只在2个方向上运动,因此只有两个自由度(一小片纸,在一大张纸内2个方向上滑动 1D卷积,卷积核只在1个方向上运动,因此只有一个自由度(一条滑窗,在一大长线上1个方向上滑动 一个卷积核运算一次 得到一个输出值 以上讨论了单个卷积核,接下来考虑多通道,一个卷积核对应一

njuptalex的博客 3万+

基于多物理参数数据融合和先进人工智能算法的锂电池热失控监测传感器

基于多物理参数数据融合和先进人工智能算法的锂电池热失控监测传感器是多种方案中的优选项!是一种快速、准确、可靠、应用广泛的传感方案!可有效监测锂离子电池热失控风险,保障化学能储能电站安全!

chicheng_danxin的博客 2422

细说Hibernate的缓存机制

2.1. 查询缓存:当使用 Session 对象执行查询操作时,如果一级缓存中没有数据,Hibernate 会在二级缓存中查找数据。2.2. 更新缓存:当使用 Session 对象执行更新操作时,Hibernate 会将更新后的数据存入一级缓存,并根据实体类的缓存策略更新二级缓存中的数据。2.3. 保存缓存:当使用 Session 对象执行保存操作时,Hibernate 会将新增的数据存入一级缓存,并根据实体类的缓存策略将数据插入到二级缓存。当 Session 对象被关闭时,一级缓存中的数据将被清除。

孤鹰的博客 2815

扣子(coze)案例^第22期:零代码打造小红书竞品监控系统+AI自动生成运营策略建议

本文详细介绍了如何利用扣子(coze)平台零代码搭建小红书竞品监控系统。该系统通过自动化工作流抓取竞品笔记数据,并存入飞书多维表格,结合AI能力自动生成包含可视化分析报告在内的运营策略建议,帮助运营者高效进行数据驱动的市场分析。

weixin_29313239的博客 1014

Spring+Hibernate下配置Hibernate二级缓存EhCache

什么样的数据适合存放到第二级缓存中? 1 很少被修改的数据 2 不是很重要的数据,允许出现偶尔并发的数据 3 不会被并发访问的数据 4 参考数据,指的是供应用参考的常量数据,它的实例数目有限,它的实例会被许多其他类的实例引用,实例极少或者从来不会被修改。 假设类A为持久化对象,对应表为tableA,这里没有考虑A和其他表关联的情况。在spring下配置使用二级缓存:<property nam

稚枭天卓 990

C#实现网络寻路(附完整源码)

C#实现网络寻路(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 432

由异常的测试眼图引发的深入思考

信号测试中出现“双眼皮”的眼图测试效果,可能的导致因素总结如下:PCB通道阻抗设计不匹配,负载端出现严重反射;发射端采用了不当的信号预处理;接收器均衡处理不当;通道串扰严重... 基于以上的假设,本文就逐一分析下这些因素到底是如何对正常的信号眼图造成影响的。

一只豌豆象的博客 3067

SpringBoot+EHcache实现缓存

撰文背景公司开发中的一个驱动模块,需要用到本地缓存,来提高驱动模块的访问速度和性能,然后就想到了Ehcache缓存,Ehcache是Hibernate 中默认的CacheProvider,hibernate就是使用Ehcache来实现二级缓存的。本质上来说Ehcache是一个缓存管理器,不仅仅可以和Hibernate配合实现缓存,也可以和其他框架比如spring boot 结合,作为一个缓存管理器...

飞往天空的雨的博客 3万+

微信小程序数据采集实战:抓包+接口分析+动态数据全流程

微信小程序爬虫虽然比普通网页爬虫复杂,但只要掌握了正确的方法,其实并没有想象中那么难。核心思路就是:先绕过证书校验抓包,然后反编译小程序找到加密逻辑,最后用Python模拟相同的加密和解密过程。需要特别提醒的是,本文仅供技术研究使用。请遵守《网络安全法》和相关法律法规,不要爬取他人的敏感数据,不要将爬虫技术用于非法用途。尊重他人的知识产权和数据安全,才能让技术发挥真正的价值。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1112

Multi-Agent Orchestrator 实战:3 步让复杂对话各归其位

Multi-Agent Orchestrator 是一个多代理编排框架,把用户输入按意图分派给不同专业 AI 代理,同时保住跨轮对话上下文,帮你用 AI 代理系统搭建一套"分工明确"的对话服务。 ## 它到底能干什么 想象你在一个客服系统里同时接了机票、天气、数学计算三类问题,单一模型要么答非所问,要么提示词越写越长。Multi-Agent Orchestrator 的做法是:输入先过一遍分类

gitblog_00514的博客 519

dex2oat编译优化调试

dex2oat编译调试的一些技巧和方法

jidapenglin28的专栏 5059

C#实现每日定时执行制定程序(附完整源码)

C#实现每日定时执行制定程序(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 873

Hibernate SessionFactory 核心原理与生产级实践指南

SessionFactory 是 Hibernate 的核心运行时契约,本质是应用启动时固化实体映射、SQL方言、二级缓存及连接策略的不可变元数据中心。其单例设计源于JVM类加载器隔离与元数据一致性要求,直接决定一级/二级缓存有效性、事务语义边界和N+1查询根因。技术价值体现在资源复用性、执行策略统一性和架构稳定性上,广泛应用于高并发交易系统、多租户SaaS平台及批处理ETL场景。深入理解SessionFactory的初始化阶段、线程模型(getCurrentSession vs openSession)及

weixin_33937499的博客 330

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Hibernate底层原理:从延迟加载到二级缓存的深度解析

Hibernate作为Java生态主流ORM框架,其本质是一套对象-关系映射决策系统,而非简单SQL生成器。理解其核心机制需回归JPA规范与数据库交互的基本原理:延迟加载是对象图导航的性能契约,依赖Session生命周期与代理机制;一级缓存是事务内状态快照管理,失效由flush、merge、refresh等操作主动驱动;二级缓存则需根据架构形态(单体/微服务/分布式)权衡一致性、性能与运维成本。这些机制共同决定了持久层的可靠性、可观察性与扩展边界。本文聚焦Hibernate 5.6+在真实生产环境中的行为逻

weixin_30542079的博客 430

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

上一篇: 基于Virtual Box搭建centos 7集群以及各类分布式系统环境搭建
下一篇: java线程取消与关闭
yiduyangyi
博客等级 码龄18年 17粉丝 20原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值