• Hibernate 配置文件详解


    Hibernate 配置文件:

    • hibernate.xml
    • xxx.hbm.xml

    一、hibernate.xml:

    hibernate.xml用来配置Hibernate的全局环境。

    1.配置连接数据库的基本信息:

    
    <property name="connection.url">jdbc:mysql://localhost:3306/ssmproperty>
    <property name="connection.driver_class">com.mysql.cj.jdbc.Driverproperty>
    <property name="connection.username">Cailinhaoproperty>
    <property name="connection.password">CAIlinhao11014359property>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.集成C3P0,配置数据库连接池信息:

    
    
    <property name="hibernate.c3p0.acquire_increment">10property>
    
    <property name="c3p0.idle_test_period">10000property>
    
    <property name="c3p0.timeout">5000property>
    
    <property name="c3p0.max_size">30property>
    
    <property name="c3p0.min_size">5property>
    
    <property name="hibernate.c3p0.max_statements">10property>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    3.配置Hibernate基本信息:

    
    <property name="show_sql">trueproperty>
    
    <property name="format_sql">trueproperty>
    
    <property name="dialect">org.hibernate.dialect.MySQL8Dialectproperty>
    
    <property name="hibernate.hbm2ddl.auto">updateproperty>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    4.注册实体关系映射文件:

    
    <mapping resource="org/example/Entity/CustomerEntity.hbm.xml"/>
    <mapping resource="org/example/Entity/OrdersEntity.hbm.xml"/>
    <mapping resource="org/example/Entity/AccountCourseEntity.hbm.xml"/>
    <mapping resource="org/example/Entity/AccountsEntity.hbm.xml"/>
    <mapping resource="org/example/Entity/CoursesEntity.hbm.xml"/>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    二、xxx.hbm.xml:

    实体关系映射文件,用来将实体类和数据库表建立映射关系。

    
    DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    
    
    
    
    
    
    
    <hibernate-mapping package="org.example.Entity">
        <class name="org.example.Entity.CustomerEntity" table="customer" schema="ssm">
            
            <id name="id" column="id" type="java.lang.Integer">
                <generator class="uuid"/>
            id>
            
            <property name="name" column="name" type="java.lang.String"/>
            <property name="age" column="age" type="java.lang.Integer"/>
            
            <set name="orders" table="orders" lazy="true" inverse="true" cascade="delete">
                
                <key column="customer_id"/>
                
                <one-to-many class="org.example.Entity.OrdersEntity"/>
            set>
        class>
    hibernate-mapping>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
  • 相关阅读:
    Safetynet论文精读
    【Redis(8)】Spring Boot整合Redis和Guava,解决缓存穿透、缓存击穿、缓存雪崩等缓存问题
    PDF转换工具哪个好?值得推荐的3款PDF转换软件
    【故障公告】遭遇用心良苦的疯狂攻击:DDoS + CC攻击
    elasticSearch配置
    华为机试真题 Java 实现【DNA序列】
    基于国产芯片RK1126的智能视频分析网关
    Linux中的nc命令
    最新AI创作系统/AI绘画系统/ChatGPT系统+H5源码+微信公众号版+支持Prompt应用
    Java顺序表和链表
  • 原文地址:https://blog.csdn.net/m0_53881899/article/details/127978285