SpringDataJPA+Hibernate框架源码剖析(二)框架整合 之 EntityManagerFactory的构建

spring boot集成hibernate springboot集成hibernate,不使用jpa方式 阅读详情

SpringDataJPA+Hibernate框架源码剖析系列文章:

  1. SpringDataJPA+Hibernate框架源码剖析(一)框架介绍
  2. SpringDataJPA+Hibernate框架源码剖析(二)框架整合 之 EntityManagerFactory的构建
  3. SpringDataJPA+Hibernate框架源码剖析(三)框架整合 之 Repository接口实现的生成
  4. SpringDataJPA+Hibernate框架源码剖析(四)框架整合 之 事务管理器的构建(包括spring的事务机制)
  5. SpringDataJPA+Hibernate框架源码剖析(五)框架整合 之 SpringBoot整合JPA剖析
  6. SpringDataJPA+Hibernate框架源码剖析(六)@PersistenceContext和@Autowired注入EntityManager的区别

SpringDataJPA+Hibernate框架整合主要关注三个方面:EntityManagerFactory的构建、Repository接口实现的生成、事务管理器的构建。

注:spring是采用注解式配置;为了控制篇幅本系列主要分析JPA和hibernate相关源码,需要配置过程和pom依赖的同学请自行百度。

EntityManagerFactory的构建

EntityManager是JPA中用于增删改查的接口,它的作用相当于一座桥梁,连接内存中的java对象和数据库的数据存储。EntityManager由容器调用EntityManagerFactory的方法获取,所以首先要构建EntityManagerFactory。

在这里插入图片描述

上图为构建EntityManagerFactory并且将构建成功的EntityManagerFactory交于spring容器管理的过程。主要关注两点:

  • LocalContainerEntityManagerFactoryBean是利用EntityManagerFactoryBuilder构造出来的。

  • 方法的返回值为LocalContainerEntityManagerFactoryBean利用了spring的FactoryBean机制,LocalContainerEntityManagerFactoryBean在初始化时做了什么。

先看EntityManagerFactoryBuilder干了什么,首先构造EntityManagerFactoryBuilder构造函数如下图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Tp5NL9x6-1645446531125)(/Users/yangxiaofei/Library/Application Support/typora-user-images/image-20220104171456279.png)]

一个四个入参前两个必填后两个可为空,后面步骤用到是再详细介绍

  1. jpaVendorAdapter:JPA适配器,具体ORM框架需要具体实现类,包含方言和具体ORM框架的一些配置如:showSql、databasePlatform
  2. jpaProperties: jap的配置信息如:hibernate.show_sql、hibernate.dialect
  3. persistenceUnitManager:persistence.xml文件解析器,可以解析管理多个持久化单元
  4. persistenceUnitRootLocation:persistence.xml的地址

然后为EntityManagerFactoryBuilder设置数据池和实体类包路径等属性后调用build,build方法也很简单创建一个LocalContainerEntityManagerFactoryBean然后将刚刚设置的各个属性赋值给LocalContainerEntityManagerFactoryBean,如下所示

public LocalContainerEntityManagerFactoryBean build() {
   LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
   if (EntityManagerFactoryBuilder.this.persistenceUnitManager != null) {
      entityManagerFactoryBean
            .setPersistenceUnitManager(EntityManagerFactoryBuilder.this.persistenceUnitManager);
   }
   if (this.persistenceUnit != null) {
      entityManagerFactoryBean.setPersistenceUnitName(this.persistenceUnit);
   }
   entityManagerFactoryBean.setJpaVendorAdapter(EntityManagerFactoryBuilder.this.jpaVendorAdapter);

   if (this.jta) {
      entityManagerFactoryBean.setJtaDataSource(this.dataSource);
   }
   else {
      entityManagerFactoryBean.setDataSource(this.dataSource);
   }
   entityManagerFactoryBean.setPackagesToScan(this.packagesToScan);
   entityManagerFactoryBean.getJpaPropertyMap().putAll(EntityManagerFactoryBuilder.this.jpaProperties);
   entityManagerFactoryBean.getJpaPropertyMap().putAll(this.properties);
   if (!ObjectUtils.isEmpty(this.mappingResources)) {
      entityManagerFactoryBean.setMappingResources(this.mappingResources);
   }
   URL rootLocation = EntityManagerFactoryBuilder.this.persistenceUnitRootLocation;
   if (rootLocation != null) {
      entityManagerFactoryBean.setPersistenceUnitRootLocation(rootLocation.toString());
   }
   if (EntityManagerFactoryBuilder.this.bootstrapExecutor != null) {
      entityManagerFactoryBean.setBootstrapExecutor(EntityManagerFactoryBuilder.this.bootstrapExecutor);
   }
   if (EntityManagerFactoryBuilder.this.persistenceUnitPostProcessors != null) {
      entityManagerFactoryBean.setPersistenceUnitPostProcessors(
            EntityManagerFactoryBuilder.this.persistenceUnitPostProcessors);
   }
   return entityManagerFactoryBean;
}

然后看LocalContainerEntityManagerFactoryBean在初始化时做了什么(FactoryBean机制不做赘述自行百度),LocalContainerEntityManagerFactoryBean的部分继承关系图如下,所以我们主要关注**afterPropertiesSet()和getObject()**方法(afterPropertiesSet()和getObject()在spring初始化工厂bean时调用,具体细节自行百度)
在这里插入图片描述

getObject()很简单如下

在这里插入图片描述

LocalContainerEntityManagerFactoryBean.afterPropertiesSet()如下

在这里插入图片描述

@Override
	public void afterPropertiesSet() throws PersistenceException {
		PersistenceUnitManager managerToUse = this.persistenceUnitManager;
		if (this.persistenceUnitManager == null) {
      // 一.如果未设置PersistenceUnitManager则采用默认的PersistenceUnitManager并且调用其初始化方法
			this.internalPersistenceUnitManager.afterPropertiesSet();
			managerToUse = this.internalPersistenceUnitManager;
		}
		 // 二.获取persistenceUnitInfo
		this.persistenceUnitInfo = determinePersistenceUnitInfo(managerToUse);
    // 三.获取JpaVendorAdapter=this.jpaVendorAdapter
		JpaVendorAdapter jpaVendorAdapter = getJpaVendorAdapter();
		if (jpaVendorAdapter != null && this.persistenceUnitInfo instanceof SmartPersistenceUnitInfo) {
			String rootPackage = jpaVendorAdapter.getPersistenceProviderRootPackage();
			if (rootPackage != null) {
        // 四.为persistenceUnitInfo设置持久性提供程序包名(rootPackage=org.hibernate)
				((SmartPersistenceUnitInfo) this.persistenceUnitInfo).setPersistenceProviderPackageName(rootPackage);
			}
		}
		//调用AbstractEntityManagerFactoryBean.afterPropertiesSet()
		super.afterPropertiesSet();
	}

有关persistenceUnitManager和persistenceUnitInfo这里重点讲一下,看了PersistenceUnitManager源码可以知道这个类的作用就是解析classpath*:META-INF/persistence.xml路径下的persistence.xml并且生成持久化单元persistenceUnitInfo,要知道一个persistence.xml可以配置多个持久化单元,而一个服务也可以有多个persistence.xml所以PersistenceUnitManager在设计上是支持持有多个persistenceUnitInfo单元的在其内部也有一个Map<String, PersistenceUnitInfo> persistenceUnitInfos用来保存多个持久化单元信息。但由于persistence.xml对实体类包名的配置比较蹩脚随着和spring框架整合方式的不断变更persistence.xml的使用渐渐越来越少,在现有的整合方式中由于不再使用persistence.xml所以在构建EntityManagerFactoryBuilder时第3第4个参数也不用传入了,在LocalContainerEntityManagerFactoryBean初始化时始终使用默认internalPersistenceUnitManager来返回一个默认的persistenceUnitInfo实体管理单元(虽然internalPersistenceUnitManager可以管理多个persistenceUnitInfo,但是LocalContainerEntityManagerFactoryBean只需要一个),也就是上图步骤一,二下文展开分析干了什么。也就是在springDataJpa的设计上是一个EntityManagerFactory只能持有一个实体管理单元persistenceUnitInfo,即如果需要多数据源配置时需要多个EntityManagerFactory才行。这也是网上搜索“springDataJpa整合多数据源配置”都是向spring注册多个EntityManagerFactory和EntityManager的原因。(这里再提一下管用EntityManagerFactoryBuilder的第三个参数persistenceUnitManager在通常情况下是可以不传的,在特殊需求下也可自定义,下文在解析一,二步骤时会提到)

步骤一internalPersistenceUnitManager.afterPropertiesSet();
步骤二主要完成的工作根据此管理器的配置准备PersistenceUnitInfo关键方法为DefaultPersistenceUnitManager.readPersistenceUnitInfos()

private List<SpringPersistenceUnitInfo> readPersistenceUnitInfos() {
		List<SpringPersistenceUnitInfo> infos = new ArrayList<>(1);
		String defaultName = this.defaultPersistenceUnitName;
   // 因为在EntityManagerFactoryBuilder的时候设置了packagesToScan所以此处buildDefaultUnit=true;
		boolean buildDefaultUnit = (this.packagesToScan != null || this.mappingResources != null);
		boolean foundDefaultUnit = false;
		PersistenceUnitReader reader = new PersistenceUnitReader(this.resourcePatternResolver, this.dataSourceLookup);
  // persistenceXmlLocations=classpath*:META-INF/persistence.xml
  // 解析persistenceXmlLocations路径下的全部文件封装成SpringPersistenceUnitInfo对象,在比较流行的springdatajpa整合方式中不再使用persistence.xml进行持久化单元配置所以此处结果为空数组。
		SpringPersistenceUnitInfo[] readInfos = reader.readPersistenceUnitInfos(this.persistenceXmlLocations);
		for (SpringPersistenceUnitInfo readInfo : readInfos) {
			infos.add(readInfo);
			if (defaultName != null && defaultName.equals(readInfo.getPersistenceUnitName())) {
				foundDefaultUnit = true;
			}
		}

		if (buildDefaultUnit) {
			if (foundDefaultUnit) {
				if (logger.isWarnEnabled()) {
					logger.warn("Found explicit default persistence unit with name '" + defaultName + "' in persistence.xml - " +
							"overriding local default persistence unit settings ('packagesToScan'/'mappingResources')");
				}
			}
			else {
        // 构建默认的PersistenceUnitInfo,在persistence.xml中比较关键的三个配置及在buildDefaultPersistenceUnitInfo时如何替代
        // 1.<provider>持久化提供者org.hibernate.jpa.HibernatePersistenceProvider  代替==》在JpaVendorAdapter中指定
        // 2.<properties>数据库信息和一些jpa的配置  代替==》使用JpaVendorAdapter中的配置和spring中的DataSource
        // 3.实体类声明  代替==》扫描packagesToScan包下的实体类
        // buildDefaultPersistenceUnitInfo主要完成的事情是构建一个默认的PersistenceUnitInfo包括3的关键信息,2信息在internalPersistenceUnitManager.afterPropertiesSet()方法调用完readPersistenceUnitInfos()方法【当前方法】后的后续逻辑中赋值,1信息在后续AbstractEntityManagerFactoryBean.afterPropertiesSet()中赋值,默认名称为default
				infos.add(buildDefaultPersistenceUnitInfo());
			}
		}
		return infos;
	}
private SpringPersistenceUnitInfo buildDefaultPersistenceUnitInfo() {
		SpringPersistenceUnitInfo scannedUnit = new SpringPersistenceUnitInfo();
		if (this.defaultPersistenceUnitName != null) {
			// 赋值默认名称defual
      scannedUnit.setPersistenceUnitName(this.defaultPersistenceUnitName);
		}
		scannedUnit.setExcludeUnlistedClasses(true);

		if (this.packagesToScan != null) {
			for (String pkg : this.packagesToScan) {
        // 扫描classpath下的packagesToScan路径下的全部类,里面会根据下图中的注解进行过滤,带有注解的类都会被放入SpringPersistenceUnitInfo中。注意jpa的@Entity注解注明的类是交由EntityManagerFactory管理并不是给spring容器管理。
				scanPackage(scannedUnit, pkg);
			}
		}
		// 在不使用persistence.xml时为空
		if (this.mappingResources != null) {
			for (String mappingFileName : this.mappingResources) {
				scannedUnit.addMappingFileName(mappingFileName);
			}
		}
		else {
			Resource ormXml = getOrmXmlForDefaultPersistenceUnit();
      // 在不使用persistence.xml时为空
			if (ormXml != null) {
				scannedUnit.addMappingFileName(DEFAULT_ORM_XML_RESOURCE);
				if (scannedUnit.getPersistenceUnitRootUrl() == null) {
					try {
						scannedUnit.setPersistenceUnitRootUrl(
								PersistenceUnitReader.determinePersistenceUnitRootUrl(ormXml));
					}
					catch (IOException ex) {
						logger.debug("Failed to determine persistence unit root URL from orm.xml location", ex);
					}
				}
			}
		}

		return scannedUnit;
	}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Frradgd0-1645446531126)(/Users/yangxiaofei/Library/Application Support/typora-user-images/image-20220105154223742.png)]

至此LocalContainerEntityManagerFactoryBean.afterPropertiesSet()的一步骤完毕。
步骤二则是在初始化完成后的PersistenceUnitManager中获取一个PersistenceUnitInfo,获取就是上面生成的这个默认的SpringPersistenceUnitInfo。

至此LocalContainerEntityManagerFactoryBean.afterPropertiesSet()的关键步骤分析完毕,然后分析super.afterPropertiesSet()即AbstractEntityManagerFactoryBean.afterPropertiesSet()

	@Override
	public void afterPropertiesSet() throws PersistenceException {
    // 获取EntityManagerFactoryBuilder构建时传进来的jpaVendorAdapter
		JpaVendorAdapter jpaVendorAdapter = getJpaVendorAdapter();
		if (jpaVendorAdapter != null) {
			if (this.persistenceProvider == null) {
        // 这个persistenceProvider是关键是持久化提供者,前面在构建PersistenceUnitInfo的解释里提到persistence.xml的三大关键其中一个就是<provider>持久化提供者就是在取得JpaVendorAdapter中的 SpringHibernateJpaPersistenceProvider。
				this.persistenceProvider = jpaVendorAdapter.getPersistenceProvider();
			}
      // 获取LocalContainerEntityManagerFactoryBean.afterPropertiesSet()初始化时创建的默认PersistenceUnitInfo“defual”
			PersistenceUnitInfo pui = getPersistenceUnitInfo();
      // 获取之前往PersistenceUnitInfo和jpaVendorAdapter中塞的各种jpa实现的配置如方言、showsql等
			Map<String, ?> vendorPropertyMap = (pui != null ? jpaVendorAdapter.getJpaPropertyMap(pui) :
					jpaVendorAdapter.getJpaPropertyMap());
      // 将这些配置合并规整
			if (!CollectionUtils.isEmpty(vendorPropertyMap)) {
				vendorPropertyMap.forEach((key, value) -> {
					if (!this.jpaPropertyMap.containsKey(key)) {
						this.jpaPropertyMap.put(key, value);
					}
				});
			}
      // 获取entityManagerFactory的实现,并判断当前类的定义类加载器是否可以加载到,防止因平行类加载器导致命名空间不可见
      // 此处entityManagerFactoryInterface为SessionFactory.class
      // 可以看下HibernateJpaVendorAdapter的构造函数
			if (this.entityManagerFactoryInterface == null) {
				this.entityManagerFactoryInterface = jpaVendorAdapter.getEntityManagerFactoryInterface();
				if (!ClassUtils.isVisible(this.entityManagerFactoryInterface, this.beanClassLoader)) {
					this.entityManagerFactoryInterface = EntityManagerFactory.class;
				}
			}
      // 获取entityManager的实现,并判断当前类的定义类加载器是否可以加载到,防止因平行类加载器导致命名空间不可见
      // 此处entityManagerInterface为Session.class 
			if (this.entityManagerInterface == null) {
				this.entityManagerInterface = jpaVendorAdapter.getEntityManagerInterface();
				if (!ClassUtils.isVisible(this.entityManagerInterface, this.beanClassLoader)) {
					this.entityManagerInterface = EntityManager.class;
				}
			}
      // 获取方言
			if (this.jpaDialect == null) {
				this.jpaDialect = jpaVendorAdapter.getJpaDialect();
			}
		}
		// 是否异步初始化,基本用不上
		AsyncTaskExecutor bootstrapExecutor = getBootstrapExecutor();
		if (bootstrapExecutor != null) {
			this.nativeEntityManagerFactoryFuture = bootstrapExecutor.submit(this::buildNativeEntityManagerFactory);
		}
		else {
      // 构建对应ORM实现的EntityManagerFactory这里构建的是SessionFactoryImpl
      // SessionFactoryImpl的构建过程贼鸡儿复杂,没办法全部贴出来,后面执行源码分析过程中用到那些分析那些
			this.nativeEntityManagerFactory = buildNativeEntityManagerFactory();
		}

		// Wrap the EntityManagerFactory in a factory implementing all its interfaces.
		// This allows interception of createEntityManager methods to return an
		// application-managed EntityManager proxy that automatically joins
		// existing transactions.
    // 为nativeEntityManagerFactory包装一次代理,使用的是JDK的动态代理,目的是可以为nativeEntityManagerFactory的方法进行监听添加横切逻辑
		this.entityManagerFactory = createEntityManagerFactoryProxy(this.nativeEntityManagerFactory);
	}
protected EntityManagerFactory createEntityManagerFactoryProxy(@Nullable EntityManagerFactory emf) {
		Set<Class<?>> ifcs = new LinkedHashSet<>();
		Class<?> entityManagerFactoryInterface = this.entityManagerFactoryInterface;
		if (entityManagerFactoryInterface != null) {
			ifcs.add(entityManagerFactoryInterface);
		}
		else if (emf != null) {
			ifcs.addAll(ClassUtils.getAllInterfacesForClassAsSet(emf.getClass(), this.beanClassLoader));
		}
		else {
			ifcs.add(EntityManagerFactory.class);
		}
		ifcs.add(EntityManagerFactoryInfo.class);

		try {
      // 为EntityManagerFactory包装一层代理,InvocationHandler为ManagedEntityManagerFactoryInvocationHandler
			return (EntityManagerFactory) Proxy.newProxyInstance(this.beanClassLoader,
					ClassUtils.toClassArray(ifcs), new ManagedEntityManagerFactoryInvocationHandler(this));
		}
		catch (IllegalArgumentException ex) {
			if (entityManagerFactoryInterface != null) {
				throw new IllegalStateException("EntityManagerFactory interface [" + entityManagerFactoryInterface +
						"] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the "+
						"'entityManagerFactoryInterface' property to plain [javax.persistence.EntityManagerFactory]", ex);
			}
			else {
				throw new IllegalStateException("Conflicting EntityManagerFactory interfaces - " +
						"consider specifying the 'jpaVendorAdapter' or 'entityManagerFactoryInterface' property " +
						"to select a specific EntityManagerFactory interface to proceed with", ex);
			}
		}
	}

至此EntityManagerFactory构建完毕其实现为SessionFactoryImpl的代理类,通过LocalContainerEntityManagerFactoryBean的getObject方法给到Spring容器。

注:不要多此一举使用@Bean注解添加EntityManager的注入,原因在SpringDataJPA+Hibernate框架源码剖析(四)@PersistenceContext和@Autowired注入EntityManager的区别中会解释。

    @Bean
		 public EntityManager entityManager(EntityManagerFactory entityManagerFactory){
       // 此处EntityManager的实现为SessionImpl
      return  entityManagerFactory.createEntityManager();
    }
模拟量传输4-20ma电流 大家可能会非常熟悉RS232,RS485,CAN等工业上常用的总线,他们都是传输数字信号的方式。那么,我们用什么方式来传输模拟信号呢?工业上普遍需要测量各类非电物理量,例如温度、压力、速度、角度等,这些都需要转换成模拟量电信号才能传输到几百米外的控制室或显示设备上。工业上最广泛采用的是用4~20mA电流来传输模拟量。 采用电流信号的原因是不容易受干扰,因为工业现场的噪声电压的幅度可能达到数V,但是噪声的功率很弱,所以噪声电流通常小于nA级别,因此给4-20mA传输带来的误差非常小;电流源内阻趋于无穷. 阅读详情

相关推荐

qt工程引入opencv库步骤

第一步:新建qt工程 第二步:在工程名.pro文件中添加opencv库的路径                   INCLUDEPATH += /home/liyuanzhe/opencv-2.4.8/include/opencv \ /home/liyuanzhe/opencv-2.4.8/include/opencv2 LIBS += /home/liyuanzhe/open

superyuanzhe的专栏 5721

springboot多数据源配置

注解标识了primary数据源,当系统中存在多个数据源时,@Primary注解会将这个数据源优先注入到需要使用的地方。上述配置中定义了两个数据源,一个是primary,一个是secondary。可以根据实际情况自行替换。

程旭清的博客 1358

数理统计四大分布---正态分布、卡方分布、学生t分布和F分布

在统计学上,我们会遇到一些常见的分布,除了正态分布外,,如t检验对应的t分布,检验对应的分布,方差分析对应的F分布等。这些分布是统计学的基础,在假设检验、方差分析等领域都起着至关重要的作用。在此,我们对这四种分布做详细的介绍,并附上MATLAB代码。 四种分布的讲解摘自MATLAB 2016的统计学和机器学习工具箱,有兴趣的可以去查看英文原版。 另外,为了方便,上传文档为图片格式,可能有些模糊...

suncangan的博客 5万+

Spring Data之EntityManagerFactory创建及源码分析

背景 在Spring Data之JPA开篇中可以看到Spring Boot的启动日志,先是创建了HikariDataSource,然后紧接着构建了EntityManagerFactory 2018-10-25 09:32:20.645 INFO 37469 --- [ main] com.zaxxer.hikari.HikariDataSource : Hikar...

小方的专栏 2万+

10分钟快速搭建OpenClaw(基于Windows+飞书)

OpenClaw 是一款功能强大的 AI 智能体工具,能够帮助用户管理邮件、日历等日常事务。本文详细介绍了在 Windows11 系统上安装和配置 OpenClaw 的完整步骤,包括 Node.js 环境搭建、Git 安装、OpenClaw 部署以及飞书机器人创建与对接。通过简单的命令行操作和可视化界面配置,用户可以快速完成 AI 助手部署,实现智能办公自动化。文中还提供了飞书机器人权限设置等关键环节的图文指引,帮助用户轻松完成系统集成。

Hello, New World! 2923

vmware虚拟机网络连接问题

主机:ubuntu14.04 Vitual Network Editor

入门虽易,精通不易,且学且珍惜! 1353

SpringBoot配置实体管理器EntityManager

这里主要利用@Bean注解向IOC容器注入EntityManagerFactory, 然后通过EntityManagerFactory创建EntityManager和JPATransactionManager,这样通过@Autowired @Qualifier @Resource等注解可以使用EntityManager的相关配置。使用EntityManager中的相关接口对数据库实体进行操作的时候, EntityManager会跟踪实体对象的状态,并决定在特定时刻将对实体的操作映射到数据库操作上面。

justlpf的专栏 2231

《点云进阶》专栏文章目录

点云进阶》专栏文章目录

点云侠的博客 4903

Spring Data之EntityManager创建及源码分析

https://blog.youkuaiyun.com/f4761/article/details/84133768 背景 前一篇文章介绍了EntityManagerFactory的创建过程,有了EntityManagerFactory接下来就是要获取EntityManager了,但EntityManager的创建不再是通过@Conditional注解,而是使用的@PersistenceContext注解,那么Spring Data是如何识别@PersistenceContext注解,并注入EntityMana

yygr的博客 1043

C# 实现 Modbus 通信全教程(支持 TCP 和 RTU,含完整错误处理)

环境准备:安装 NModbus4 库,明确设备参数(IP/串口、地址、数据类型);连接设备:TCP 用 TcpClient,RTU 用 SerialPort,注意超时和参数匹配;读写数据:根据数据类型调用对应方法(读保持寄存器用 ReadHoldingRegisters);错误处理:捕获连接、超时、协议等异常,针对性排查问题。掌握这些后,即可轻松实现与工业设备的 Modbus 通信,为上位机开发提供稳定的数据交互能力。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 2060

高通SDX35:SGMII接口PHY RTL8211FSI-CG驱动适配

高通SDX35 RTL8211F SGMII

不秃头的程序猿Gabriel的博客 785

SpringDataJPA+Hibernate框架源码剖析(一)框架介绍

SpringDataJPA+Hibernate框架源码剖析系列文章: SpringDataJPA+Hibernate框架源码剖析(一)框架介绍 SpringDataJPA+Hibernate框架源码剖析(二)框架整合 之 EntityManagerFactory的构建 SpringDataJPA+Hibernate框架源码剖析(三)框架整合 之 Repository接口实现的生成 SpringDataJPA+Hibernate框架源码剖析(四)框架整合 之 事务管理器的构建 SpringDataJPA+H

yangxiaofei_java的博客 1335

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

SpringDataJPA+Hibernate框架源码剖析(五)框架整合 之 SpringBoot整合JPA剖析

SpringDataJPA+Hibernate框架源码剖析系列文章: SpringDataJPA+Hibernate框架源码剖析(一)框架介绍 SpringDataJPA+Hibernate框架源码剖析(二)框架整合 之 EntityManagerFactory的构建 SpringDataJPA+Hibernate框架源码剖析(三)框架整合 之 Repository接口实现的生成 SpringDataJPA+Hibernate框架源码剖析(四)框架整合 之 事务管理器的构建(包括spring的事务机制)

yangxiaofei_java的博客 1014

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

整合ssp过程(目前还没有整合springMVC)

写博客为了记录自己学习的路程,希望变得更强 就只写步骤和细节了 目前是整合SpringSpringData JPA(ORM为Hibernate) web,xml配置 1:spring的监听器 配置文件取名applicationContext.xml 放在类路径下面 applicationContext.xml里面配置的内容: 2:配置扫描的包,把加注解的Bean加入IOC...

qq_36664325的博客 1005

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

jdbc-jdbcTemplate-hibernate-jpa-springDataJpa系列(二)

1 前面的文章索引 jdbc开发和事务的使用 spring-jdbcTemplate开发和事务的使用 hibernate的原生xml方式开发和事务的使用 hibernate的原生xml方式与spring集成以及事务的使用 hibernate的原生注解方式开发和事务的使用 hibernate的注解方式开发与Spring集成和事务的使用 详见第一篇文章j...

weixin_34176694的博客 119

Spring Data JPA 从入门到精通~javax.persistence概况介绍

虽然 Spring Data JPA 已经对数据的操作封装的很好了,约定大于配置的思想,帮我们默认了很多东西。JPA(Java 持久性 API)是存储业务实体关联的实体的来源,它显示了如何定义一个面向普通 Java 对象(POJO)作为一个实体,以及如何与管理关系实体,提供了一套标准。因此,javax.persistence 下面的有些注解我们还是必须要去了解的,便于更好的提高工作效率。 (1)javax.persistence 我们打开源码位于 hibernate-jpa-**.jar 包里面。 依赖

小强快跑~~ 1万+

【Spring Boot】(28)、Spring Boot中spring-data-jpa自动配置源码分析

在上一节中,我们简单的讲述了jpa的查询语法和使用教程,而这一节咱们来看看Spring Boot中对jpa是如何进行自动配置的。      在Spring Boot自动配置的时候,一旦引入spring-boot-starter-data-jpa,就会完成JpaRepositoriesAutoConfiguration的自动配置。     JpaRepositoriesAutoConfig...

caychen的博客 1855

Spring Data之JPA开篇

背景 目前Spring Boot大行其道,其便捷性给开发人员带来了很大的效率提升。它简化了样板配置,通过关键的说明或者约定就能快速搭建起想要的框架。 Spring Boot可适配的组件众多,由于绝大多数应用系统都会同数据库打交道的,这就涉及到Spring Data家族的使用。为什么说是家族呢,因为Spring Data包含JDBC、JPA、LDAP、MongoDB、Redis、Elasticsea...

小方的专栏 2152

java打包有时报错Consider defining a bean named ‘entityManagerFactory‘ in your configuration.的解决方法

1.项目用默认配置时,单数据库的情况下,一般没有问题;2.此时,需要搜索注解,看看是否都配置了,如果有未配置的、需要补上或者删掉整个注解。3.关于maven打包编译顺序的问题,暂时不清楚怎么配置;虽然加了@Primary注解,并且maven打包是没有问题的;只是打包后的war/jar启动时,有时候能成功、有时候会报错找不到;如果可以正确配置maven编译顺序的话,应该也可以;如果不行、就还是按照第2步、检查下自己的项目。

BHSZZY的博客 5107

springboot多数据源启动提示error:...EntityManagerFactoryBuilder‘ that could not be found

springboot多数据源启动提示error

leisongc的博客 2206

JPA-Hibernate

一. JPA与hibernate的关系 JPA规范本质上就是一种ORM规范,注意不是ORM框架——因为JPA并未提供ORM实现,它只是制订了一些规范,提供了一些编程的API接口,但具体实现则由服务厂商来提供实现。 JPA和Hibernate的关系就像JDBC和数据库JDBC驱动的关系,JPA是规范,Hibernate除了作为ORM框架之外,它也是一种JPA实现。JPA怎么取代Hibernate呢?JDBC规范可以驱动底层数据库吗?答案是否定的,也就是说,如果使用JPA规范进行数据库操作,底层需要..

Wqr_18390921824的博客 1139

【SpringBoot整合JPA框架(hibernate实现)详解】(附详细代码)

Java Persistence API(JPA)是Java EE和Java SE平台的一部分,提供了一种简单的对象关系映射(ORM)机制,用于将Java对象持久化到关系型数据库中。JPA通过注解或XML配置文件实现实体类与数据库表之间的映射,简化了数据库操作的过程。

qq_45759093的博客 4204

springboot 多数据源的配置

1.首先配置多个数据源,properties 文件中添加多个数据源信息                        &lt;!-- jpa 依赖 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starte...

shf17782830280的博客 311

《SpringBoot4.0初识》第二篇:模块化启动器

Spring Boot 4.0通过模块化重构解决三大核心问题:1) 将单体autoconfigure拆分为29个独立模块,形成starter→feature→autoconfigure→runtime四级架构;2) 引入编译期条件决策机制,将条件注解评估从运行时提前到编译期;3) 与GraalVM深度整合,实现精准的无用代码消除。

断剑重铸之日 骑士归来之时 1013

JPA整合Hibernate快速入门

ORM概述 ORM(Object-Relational Mapping) 表示对象关系映射。在面向对象的软件开发中,通过ORM,就可以把对象映射到关系型数据库中。只要有一套程序能够做到建立对象与数据库的关联,操作对象就可以直接操作数据库数据,就可以说这套程序实现了ORM对象关系映射 简单的说:ORM就是建立实体类和数据库表之间的关系,从而达到操作实体类就相当于操作数据库表的目的。 为什么使用...

清欢 5995

Jpa使用详解(Hibernate)

Jpa使用详解 ORM思想 1.ORM概述 ORM(Object-Relational Mapping) 表示对象关系映射。在面向对象的软件开发中,通过ORM,就可以把对象映射到关系型数据库中。只要有一套程序能够做到建立对象与数据库的关联,操作对象就可以直接操作数据库数据,就可以说这套程序实现了ORM对象关系映射 简单的说:ORM就是建立实体类和数据库表之间的关系,从而达到操作实体类就相当于操作数据库表的目的。 2.为什么要使用ORM 当实现一个应用程序时(不使用O/R Mapping)

Java后端技术栈 5337
上一篇: SpringDataJPA+Hibernate框架源码剖析(一)框架介绍
下一篇: SpringDataJPA+Hibernate框架源码剖析(三)框架整合 之 Repository接口实现的生成
躺平程序猿
博客等级 码龄8年 4870粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

躺平程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值