Spring_Hibernate整合準備

1,Spring整合Hibernate   整合什麼?java

  1)由IOC容器來生成Hibernate的SessionFactorymysql

  2)讓Hibernate使用上Spring的聲明式事務sql

2,整合步驟api

1)先加入Hibernate緩存

   Jar包session

       

/Spring_Hibernate/lib/antlr-2.7.7.jar
/Spring_Hibernate/lib/c3p0-0.9.1.2.jar      ---c3p0數據源
/Spring_Hibernate/lib/dom4j-1.6.1.jar
/Spring_Hibernate/lib/geronimo-jta_1.1_spec-1.1.1.jar
/Spring_Hibernate/lib/hibernate-commons-annotations-5.0.1.Final.jar
/Spring_Hibernate/lib/hibernate-core-5.0.12.Final.jar
/Spring_Hibernate/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar
/Spring_Hibernate/lib/jandex-2.0.0.Final.jar
/Spring_Hibernate/lib/javassist-3.18.1-GA.jar
/Spring_Hibernate/lib/jboss-logging-3.3.0.Final.jar
/Spring_Hibernate/lib/mysql-connector-java-8.0.11.jar    --mysql驅動

 

   添加Hibernate的配置文件:hibernate.cfg.xmldom

   

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
    
    <!-- 配置Hibernate的基本屬性 -->
    <!-- 1.數據源需配置到IOC容器中,因此在此處再也不須要配置數據源 -->
    <!-- 2.導入關聯的映射文件 ,也在IOC容器配置session-factory裏配置-->
    <!-- 3.配置hibernate的基本屬性,:方言,格式化sql,生成表的策略,以及二級緩存的 -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    
    <property name="hibernate.hbm2ddl.auto">update</property><!--①-->
    
    <property name="hibernate.show_sql">true</property>
   
    <property name="hibernate.format_sql">true</property>
    </session-factory>
</hibernate-configuration>

 

2)加入Springspa

3)整合hibernate

相關文章
相關標籤/搜索