Spring Boot 整合Spring Data JPA之Hibernate JPA(七)
在spring boot整合spring data jpa之前先了解一下Hibernate JPA
JPA:由 Sun 公司提供了一对对于持久层操作的标准(接口+文档)
Hibernate:是 Gavin King 开发的一套对于持久层操作的自动的 ORM 框架。
Hibernate JPA:是在 Hibernate3.2 版本那种提供了对于 JPA 的标准的实现。提供了一套按
照 JPA 标准来实现持久层开发的 API
个人学习完之后到感觉:JPA其实不算是一套框架,更加像一套规则,或者是标准。
一、 Spring 整合 Hibernate JPA
在Hibernate项目中导入HIbernateJPA到jar包,这里我用但是web项目,不是maven项目。
配置xml到不同,Hibernate配置如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 配置读取properties文件的工具类 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置c3p0数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="driverClass" value="${jdbc.driver.class}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置Hibernate的SeesionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- hibernateProperties属性:配置与hibernate相关的内容,如显示sq