`
Luob.
  • 浏览: 1589935 次
  • 来自: 上海
社区版块
存档分类
最新评论

Hibernate 的关系与配置

阅读更多
1.单向 N:1
例如:一个地方有多个人住.
(在1 的一端进行配置,每个同学记住老师,比老师记住每个同学简单.效率高)


public class Address {
	private Integer addressid;
	private String addressDetail;

        //set get ...
}

public class Person {

	private Integer id;
	private String name;
	private int age;
	
	private Address address;  //单向(N:1)  反过来(1:1) 
	//set  get...
}



#主表
DROP TABLE IF EXISTS mytest.address;
CREATE TABLE mytest.address
(
aid         INTEGER NOT NULL,
addressdesc VARCHAR (400),
PRIMARY KEY (aid)
);

#子表
DROP TABLE IF EXISTS mytest.person;

CREATE TABLE mytest.person
(
pid        INTEGER NOT NULL,
name       VARCHAR (50) NOT NULL,
age        TINYINT NOT NULL DEFAULT 0,
address_id INTEGER,
PRIMARY KEY (pid),
KEY address_id (address_id),
CONSTRAINT person_ibfk_1 FOREIGN KEY (address_id) REFERENCES address (aid)
);

   <!--方式1.没有中间关联表(没有中间表)-->
   <!--在Person.hbm.xml的配置文件中加入 many:Person  one:Address -->
   <many-to-one name="address" cascade="all" class="Address" column="address_id"/>

   <!--方式2.有中间关联表(有中间表:person_address(person_id,address_id))-->
   <!--在Person.hbm.xml的配置文件中加入 many:Person  one:Address -->
   <join table="person_address">
			<key column="person_id"/>
			<many-to-one name="address" cascade="all" class="Address" column="address_id"/>
   </join>



2.单向 1:1

public class Address {
	private Integer addressid;
	private String addressDetail;

        //set get ...
}

public class Person {

	private Integer id;
	private String name;
	private int age;
	
	private Address address;  //单向(N:1)  反过来(1:1) 
	//set  get...
}

   基于外键的单向1:1
   <!--方式1.没有中间关联表(没有中间表)-->
   <!--在Person.hbm.xml的配置文件中加入 many:Person  one:Address -->
   <many-to-one name="address" unique="true" cascade="all"  class="Address" column="address_id"/>

  
   <!--方式2.有中间关联表(有中间表:person_address(person_id,address_id))-->
   <!--在Person.hbm.xml的配置文件中加入 many:Person  one:Address -->
   <join table="person_address">
			<key column="person_id"/>
			<many-to-one name="address" unique="true" cascade="all" class="Address" column="address_id"/>
   </join>

   基于主键的单向 1:1
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-12-2 22:01:23 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
	<class name="com.crazyit.app.domain.mapping.Person" table="PERSON">
		<id name="id" type="java.lang.Integer">
			<column name="ID" />
			<!-- <generator class="native" /> -->
			<generator class="foreign">
				<!--通过property 指定 映射的主键为 自己的属性  address这个对象  -->
				<param name="property">address</param>
			</generator>
		</id> 
		<property name="name" type="java.lang.String">
			<column name="NAME" />
		</property>
		<property name="age" type="int">
			<column name="AGE" />
		</property>
			
		<!--单向 主键关联(即,该表不能自己生成主键 ,只能引用其他表的主键 比如下面,是引用 Address表 主键 -->
		<one-to-one name="address"/>		
	</class>
</hibernate-mapping>





3.单向 1:N
例如:一个人有多个住的地址(土豪啦)

public class Address {
	private Integer addressid;
	private String addressDetail;

        //set get ...
}

public class Person {

	private Integer id;
	private String name;
	private int age;
	
	//如果一个人有多个地址,而一个地址 又像上面,有多个人,这样就形成了  N:N  所以 1:N 包含了(N:N)
	private Set<Address> addresses=new HashSet<Address>();//1:N(包含了 N:N)
	
	//set  get...
}

     <!--方式一:没有中间表-->
     <!--在Person.hbm.xml中配置-->
<set name="addresses">
		<key column="person_id"/>
		<one-to-many class="Address" not-found="ignore"/>
</set>

     <!--方式二:有中间表(person_address(person_id,address_id))-->
     <!--还是在Person.hbm.xml中配置-->
<set name="addresses" table="person_addesses" cascade="all">
			<key column="person_id"/>
			<many-to-many class="Address" column="address_id" unique="true"/>
</set>
   


4.单向 N:N
单向N:N的关联,必须使用中间表

public class Address {
	private Integer addressid;
	private String addressDetail;

        //set get ...
}

public class Person {

	private Integer id;
	private String name;
	private int age;
	
	//如果一个人有多个地址,而一个地址 又像上面,有多个人,这样就形成了  N:N  所以 1:N 包含了(N:N)
	private Set<Address> addresses=new HashSet<Address>();//1:N(包含了 N:N)
	
	//set  get...
}

     <!--方式二:有中间表(person_address(person_id,address_id))-->
     <!--还是在Person.hbm.xml中配置-->
<set name="addresses" table="person_addesses" cascade="all">
			<key column="person_id"/>
			<many-to-many class="Address" column="address_id"/>
</set>
   


5.双向 1:N

public class Address {
	private Integer addressid;
	private String addressDetail;

        private Person person;
        //set get ...
}

public class Person {

	private Integer id;
	private String name;
	private int age;
	
	private Set<Address> addresses=new HashSet<Address>();
	
	//set  get...
}

     <!--方式一:没有中间表-->
     <!--在Person.hbm.xml中配置-->    
     <set name="addresses" inverse="true">
			<key column="person_id"/>
			<one-to-many class="Address"/>
     </set>
     <!--在Address.hbm.xml中配置-->   
     <many-to-one name="person" class="Person" column="person_id" not-null="true"/>

     <!--方式二:有中间表(person_address(person_id,address_id))-->
     <!--在Person.hbm.xml中配置-->
<set name="addresses" inverse="true" table="person_address">
			<key column="person_id"/>
			<many-to-many column="address_id" class="Address" unique="true"/>
		</set>
     <!--在Address.hbm.xml中配置-->  
<join table="person_address">
			<key column="address_id"/>
			<many-to-one name="person" column="person_id" not-null="true"></many-to-one>
		</join>

</set>
   


6.双向 N:N
双向N:N的关联,必须使用中间表

public class Address {
	private Integer addressid;
	private String addressDetail;

        private Set<Person> persons=new HashSet<Person>();
        //set get ...
}

public class Person {

	private Integer id;
	private String name;
	private int age;
	
	private Set<Address> addresses=new HashSet<Address>();
	
	//set  get...
}

 <!--在Person.hbm.xml中配置-->    
<set name="addresses" inverse="true" table="person_address">
			<key column="person_id"/>
			<many-to-many column="address_id" class="Address"/>
		</set>

 <!--在Address.hbm.xml中配置-->  
<set name="persons" table="peson_addresses">
			<key column="address_id"/>
			<many-to-many column="person_id" class="Person"/>
		</set>



6.双向 1:1

public class Address {
	private Integer addressid;
	private String addressDetail;
        private Person  person;
        //set get ...
}

public class Person {

	private Integer id;
	private String name;
	private int age;
	
	private Address address;  
	//set  get...
}

    //基于外键的双向1:1
      <!--方式1:没有关联表-->
      <!--在Person.hbm.xml中配置-->  
      <one-to-one name="address" property/>
       
      <!--在Address.hbm.xml中配置-->  
      <many-to-one name="person" class="Person" unique="true" column="person_id" not-null="true"/>
       
      <!--方式2:有关联表-->
      <!--在Person.hbm.xml中配置-->
<join table="person_address" inverse="true">
			<key column="person_id" unique="true"/>
			<many-to-one name="address" unique="true" class="Address" column="address_id"/>
		</join>

       <!--在Address.hbm.xml中配置-->  
        <join table="person_address" optional="true">
			<key column="address_id" unique="true"/>
			<many-to-one name="person" unique="true" column="person_id" not-null="true"/>
		</join>


//基于主键的双向1:1
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-12-2 22:01:23 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
	<class name="com.crazyit.app.domain.mapping.Person" table="PERSON">
		<id name="id" type="java.lang.Integer">
			<column name="ID" />
			<!-- <generator class="native" /> -->
			<generator class="foreign">
				<!--通过property 指定 映射的主键为 自己的属性  address这个对象  -->
				<param name="property">address</param>
			</generator>
		</id> 
		<property name="name" type="java.lang.String">
			<column name="NAME" />
		</property>
		<property name="age" type="int">
			<column name="AGE" />
		</property>
			
		<!--单向 主键关联(即,该表不能自己生成主键 ,只能引用其他表的主键 比如下面,是引用 Address表 主键 -->
		<one-to-one name="address"/>		
	</class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-12-2 22:01:23 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
	<class name="com.crazyit.app.domain.mapping.Address" table="ADDRESS">
		<id name="id" type="java.lang.Integer">
			<column name="ID" />
			<generator class="native" />
		</id> 
		<property name="addressDetail" type="java.lang.String">
			<column name="ADDRESSDETAIL" />
		</property>
		
                <one-to-one name="person"/>
		
	</class>
</hibernate-mapping>


这中配置,可以互换 ,现在是person的主键,有address 生成 
反过来也可以.



7.组建属性包含关联实体
//不是持久化类
public class Address {  
    private Integer addressid;  
    private String addressDetail;  
    private Set<School> schools=new HashSet<School>();
        //set get ...  
}  
  
public class School {
	private Integer schoolId;
	private String schoolname;
//get set
}

public class Person {  
  
    private Integer id;  
    private String name;  
    private int age;  
      
    private Address address;  //单向(N:1)  反过来(1:1)   
    //set  get...  
}  

//在person中进行配置
 <!--Person 中 的address是组件 不是持久化类  -->
		<component name="address" class="Address">
			<parent name="person"/> <!--Address 类中的pseron类  -->
			<property name="addressDetail"/>
			<set name="schools">
				<key column="address_id"/>
				<one-to-many class="School"/>
			</set>
		</component>



8.复合主键的关联关系

public class Person {

	//多列 联合组件
	private String first;
	private String last;
	
	private String name;
	private int age;

	private Set<Address> addresses=new HashSet<Address>();//1:N(包含了 N:N)

//get set	
}

public class Address {
	private Integer id;
	private String addressDetail;
	private Person person;
}

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-12-2 22:01:23 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
	<class name="com.crazyit.app.domain.mapping.Person" table="PERSON">
		<composite-id>
			<key-property name="first" type="string"/>
			<key-property name="last" type="string"/>
		</composite-id>

		<property name="name" type="java.lang.String">
			<column name="NAME" />
		</property>
		<property name="age" type="int">
			<column name="AGE" />
		</property>

                <set name="addresses" inverse="true" cascade="all">
			<key>
                            <column name="fisrt"/>                                                                  
                            <column name="last"/>
                         </key>
			<one-to-many class="Address"/>
		</set>	
	</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-12-2 22:01:23 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
	<class name="com.crazyit.app.domain.mapping.Address" table="PERSON">
		<id name="id" type="java.lang.Integer">
			<column name="ID" />
			<generator class="native" />
		</id> 
		<property name="addressDetail" type="java.lang.String">
			<column name="ADDRESSDETAIL" />
		</property>
                <many-to-one name="person" class="Person" not-null="true">
                             <column name="fisrt"/>                                                                  
                            <column name="last"/>

                </many-to-one>
	</class>
</hibernate-mapping>



9.复合主键的成员属性为关联实体
public class Order {

	private Integer orderId;
	private Date orderDate;
	private Set<OrderItem> items=new HashSet<OrderItem>();
	//get set
}

public class OrderItem {
	private Order order;
	private Product product;
	private int count;
//get set
}
public class Product {
	private Integer productId;
	private String name;
//get set
}

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-12-2 22:01:23 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
	<class name="com.crazyit.app.domain.mapping.OrderItem" table="order_item_info">
		
		<composite-id>
			<key-many-to-one name="product" class="Product" column="product_id"/>
			<key-many-to-one name="order" class="Order" column="order_id"/>
			<key-property name="count" type="int"/>
		</composite-id>
	</class>
</hibernate-mapping>


10.采用subclass 进行继承映射
public class Person {

	private Integer id;
	private String name;
	private char gender;
	
	private Address address;
//get set
	
}

public class Address { 
 
	private String detail;
	private String zip;
	private String country;
//get set 
}


public class Employee extends Person {

	private String title;
	private double salary;
	private Set<Customer> customers=new HashSet<Customer>();
	private Manager manager;
//get set
}

public class Customer extends Person {

	private String commnets;
	private Employee employee;
//get set
}


public class Manager extends Employee {

	private String department;
	private Set<Employee> employees=new HashSet<Employee>();
//get set	
}




<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2014-1-12 13:35:14 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="com.crazyit.app.domain.extenr.Person" table="PERSON" discriminator-value="普通人">
        <id name="id" type="java.lang.Integer" access="field">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <discriminator column="wawa" type="string"/>
        <property name="name" type="java.lang.String" access="field">
            <column name="NAME" />
        </property>
        <property name="gender" type="char" access="field">
            <column name="GENDER" />
        </property>
        <component name="address">
        	<property name="detail"/>
        	<property name="zip"/>
        	<property name="country"/>
        </component>
       
       <subclass name="Employee" discriminator-value="雇员">
       		<property name="title"/>
       		<property name="salary"/>
       		<many-to-one name="manager" column="manager_id"/>
       		<set name="customer" inverse="true">
       			<key column="employee_id"/>
       			<one-to-many class="Customer"/>
       		</set>
       		<subclass name="Manager" discriminator-value="经理">
       			<property name="department"/>
       			<set name="employees" inverse="false">
       				<key column="manager_id"/>
       				<one-to-many class="Employee"/>
       			</set>
       		</subclass>
       		
       </subclass>
       <subclass name="Customer" discriminator-value="顾客">
       		<property name="comments"/>
       		<many-to-one name="employee" column="employee_id"/>
       </subclass>
       <!-- 采用这中配置的缺点:定义的子类字段不能有非空约束 否则保存其他子类的 时候出现冲突,
       				优点:不用采用多表连接查询,性能比较好
           父类和子类的所有属性都在一个表中
        -->
    </class>
</hibernate-mapping>



11.采用joined-subclass 进行继承映射
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2014-1-12 13:35:14 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="com.crazyit.app.domain.extenr.Person" table="PERSON" discriminator-value="普通人">
        <id name="id" type="java.lang.Integer" access="field">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <discriminator column="wawa" type="string"/>
        <property name="name" type="java.lang.String" access="field">
            <column name="NAME" />
        </property>
        <property name="gender" type="char" access="field">
            <column name="GENDER" />
        </property>
        <component name="address">
        	<property name="detail"/>
        	<property name="zip"/>
        	<property name="country"/>
        </component>
       <joined-subclass name="Employee">
       	   <key column="employee_id"/>
       	   <property name="title" not-null="true"/>
       	   <property name="salary" not-null="true"/>
       	   <many-to-one name="manager" column="manager_id"/>
       	   <set name="customers" inverse="true">
       	   		<key column="employee_id"/>
       	   		<one-to-many class="Customer"/>
       	   </set>
       	   <joined-subclass name="Manager">
       	   		<key column="manager_id"/>
       	   		<property name="department"/>
       	   		<set name="employees" inverse="true">
       	   			<key column="manager_id"/>
       	   			<one-to-many class="Employee"/>
       	   		</set>
       	   </joined-subclass>
       </joined-subclass>
       
       <joined-subclass name="Customer">
       		<key column="customer_id"/>
       		<property name="commnets" not-null="true"/>
       		<many-to-one name="employee" column="employee_id" not-null="true"/>
       </joined-subclass>
    </class>
</hibernate-mapping>

<!--这中配置特点是:子类的特性保存在子表中,共性保存在父类中,子类的属性可以加入非空约束了-->


21.采用union-subclass 进行继承映射
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2014-1-12 13:35:14 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="com.crazyit.app.domain.extenr.Person" table="PERSON" discriminator-value="普通人">
        <id name="id" type="java.lang.Integer" access="field">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <discriminator column="wawa" type="string"/>
        <property name="name" type="java.lang.String" access="field">
            <column name="NAME" />
        </property>
        <property name="gender" type="char" access="field">
            <column name="GENDER" />
        </property>
        <component name="address">
        	<property name="detail"/>
        	<property name="zip"/>
        	<property name="country"/>
        </component>
       <union-subclass name="Employee" table="employee_inf">
       		<property name="title" not-null="true"/>
       		<property name="salary" not-null="true"/>
       		<many-to-one name="manager" column="manager_id"/>
       		<set name="customers" inverse="true">
       			<key column="employee_id"/>
       			<one-to-many class="Customer"/>
       		</set>
       		<union-subclass name="Manager" table="manager_inf">
       			<property name="department"/>
       			<set name="employees" inverse="true">
       				<key column="manage_id"/>
       				<one-to-many class="Employee"/>
       			</set>
       		</union-subclass>
       </union-subclass>
       <union-subclass name="Customer" table="customer_inf">
       	<property name="commnents" not-null="true"/>
       	<many-to-one name="employee" column="employee_id" not-null="true"/>
       </union-subclass>
    </class>
</hibernate-mapping>

<!--
  子类的特性和共性,在子表中都会存在,和 joined-subclass的最他区别.
 使用union-subclass 持久化的主键生成方式不能是 identity ,sequence,native.
 -->
0
2
分享到:
评论

相关推荐

    Hibernate程序的配置文件

    通过`&lt;mapping resource="entity/EntityName.hbm.xml"/&gt;`来指定每个实体类的映射文件,这些文件描述了Java对象与数据库表之间的映射关系。 5. **缓存配置**:Hibernate支持一级缓存(Session级别)和二级缓存...

    Hibernate映射关系配置:XML方式和注解方式

    标题“Hibernate映射关系配置:XML方式和注解方式”涉及到的是Java持久层框架Hibernate中的一个重要概念——对象关系映射(ORM)。在这个主题中,我们将探讨如何通过XML映射文件和注解来配置Hibernate实体之间的关系...

    Hibernate关联关系配置

    ### Hibernate关联关系配置详解 #### 一、一对多与多对一关系配置 在软件开发过程中,实体之间的关联关系是常见的需求之一。其中,“一对多”与“多对一”的关系尤为常见,这类关系通常用来表示实体之间的层级或...

    Hibernate_关联关系映射配置详解

    Hibernate_关联关系映射配置详解,希望能帮助广大java爱好者

    hibernate配置文件详解

    hibernate.cfg.xml 文件是 Hibernate 的基本配置文件,它包含了 Hibernate 与数据库的基本连接信息。在 Hibernate 工作的初始阶段,这些信息被加载到 Configuration 和 SessionFactory 实例中。该文件的基本结构如下...

    Hibernate核心配置文件对照表

    `hibernate.properties`是Hibernate的核心配置文件,用于设定与数据库连接、缓存策略、事务管理等相关的重要参数。下面我们将详细探讨这个配置文件中的关键知识点。 1. **数据库连接配置** - `hibernate....

    Hibernate的配置详解

    在本篇中,我们将深入探讨Hibernate的配置,特别是涉及一对一、一对多和多对多关系的配置。 首先,配置过程始于`Configuration`接口。这个接口用于设置Hibernate所需的配置信息,如数据源、连接参数等,并根据配置...

    hibernate与各种数据库的连接配置

    Hibernate 与各种数据库的连接配置 Hibernate 是一个 популяр的对象关系映射(ORM)工具,用于将 Java 对象映射到关系数据库中。为了使用 Hibernate,需要配置连接数据库的设置。下面将介绍 Hibernate 与...

    Hibernate自动生成配置文件

    在Java开发领域,Hibernate作为一款优秀的对象关系映射(Object-Relational Mapping,简称ORM)框架,极大地简化了Java应用与数据库之间的交互过程。通过将Java对象模型映射到数据库的表结构上,Hibernate允许开发者...

    Hibernate基本配置演示

    **Hibernate基本配置演示** 在Java开发中,Hibernate是一款强大的对象关系映射(ORM)框架,它简化了数据库操作,使得开发者能够用Java对象来处理数据。这篇教程将深入讲解Hibernate的基本配置过程,确保你能顺利...

    hibernate_esb配置

    在Java企业级开发中,Hibernate作为一个强大的对象关系映射(ORM)框架,被广泛用于简化数据库操作。而ESB(Enterprise Service Bus,企业服务总线)则作为企业集成的核心组件,负责不同系统间的通信与数据交换。将...

    spring整合struts2与hibernate核心配置文件

    而Hibernate则是一个ORM(对象关系映射)框架,它简化了数据库操作,使开发者可以专注于业务代码而不是SQL。 **Spring框架** Spring是Java企业版(Java EE)开发中的关键组件,它的核心特性包括依赖注入(DI)和...

    hibernate_3配置文件参数汇总

    2. **JDBC属性**:`hibernate.connection.*` 系列参数用于配置与数据库的连接。包括`driver_class`(JDBC驱动类)、`url`(JDBC URL)、`username`(数据库用户名)和`password`(数据库密码)。当使用连接池如C3P0...

    oracle的hibernate配置文件

    《Oracle与Hibernate集成的配置详解》 在Java开发领域,Hibernate作为一款强大的对象关系映射(ORM)框架,极大地简化了数据库操作。当与Oracle这样的大型数据库系统结合使用时,正确的配置是确保程序正常运行的...

    配置hibernate数据源

    而Hibernate/MyBatis是JDBC的高级封装,它通过对象关系映射(ORM)简化了数据库操作,使得Java对象与数据库表之间的交互更为便捷。 Hibernate是一个独立的开源库,其特点在于不仅能在Web项目中使用,在普通的Java项目...

    注解配置 javabean hibernate 关联关系

    在Hibernate框架中,注解配置被广泛用于简化对象关系映射(ORM)的配置,使得Java Bean可以直接与数据库表进行关联。本篇文章将深入探讨如何使用注解配置Java Bean并建立Hibernate的关联关系。 首先,我们需要理解...

    hibernate原理与配置快速入门

    **Hibernate原理与配置快速入门** Hibernate 是一个流行的Java对象关系映射(ORM)框架,它为开发者提供了一种在Java应用程序中操作数据库的便捷方式,消除了传统的JDBC编码的繁琐性。本教程将带你快速了解...

    Hibernate的配置文件

    Hibernate作为一个优秀的对象关系映射(ORM)框架,极大地简化了数据库操作。在这个场景中,我们关注的是Hibernate的配置文件——`hibernate.cfg.xml`。这个文件是Hibernate应用的核心,它定义了数据源、...

    JAVA 使用hibernate配置实例

    在Java开发中,Hibernate是一个非常重要的对象关系映射(ORM)框架,它简化了数据库操作,使得开发者可以使用面向对象的方式来处理数据。本教程将详细讲解如何在Java项目中配置和使用Hibernate,包括在普通Java工程...

Global site tag (gtag.js) - Google Analytics