`

Hibernate映射类型

阅读更多
1. 基本类型映射

Hibernate映射类型Java类型标准SQL类型
integerjava.lang.IntegerINTEGER
longjava.lang.LongBIGINT
shortjava.lang.ShortSMALLINT
floatjava.lang.FloatFLOAT
doublejava.lang.DoubleDOUBLE
big_decimaljava.math.BigDecimalNUMBERIC
characterjava.lang.StringCHAR(1)
stringjava.lang.StringVARCHAR
bytebyte或java.lang.ByteTINYINT
booleanboolean或java.lang.BooleanBIT
yes_noboolean或java.lang.BooleanCHAR(1)('Y'或'N')
true_falseboolean或java.lang.BooleanCHAR(1)('Y'或'N')
datejava.util.Date或java.sql.DateDATE
timejava.util.Date或java.sql.TimeTIME
timestampjava.util.Date或java.sql.TimestampTIMESTAMP
calendar_datejava.util.CalendarDATE
binarybyte[]VARBINARY或BLOB
textjava.lang.StringCLOB
serializablejava.io.Serializable实例VARBINARY或BLOB
clobjava.sql.ClobCLOB
blobjava.sql.BlobBLOB
classjava.lang.ClassVARCHAR
localejava.util.LocaleVARCHAR
timezonejava.util.TimeZoneVARCHAR
currencyjava.util.CurrencyVARCHAR


新建项目Hibernate06

导入mysql高版本jar包,右键buildPath
mysql-connector-java-5.1.26-bin.jar


hibernate.cfg.xml

<?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>
        <!-- 数据库连接设置 -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/hibernate4</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>
        <!-- 方言 -->
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <!-- 控制台显示SQL -->
        <property name="show_sql">true</property>
        <!-- 自动更新表结构 -->
        <property name="hbm2ddl.auto">update</property>
        <!-- Mapper -->
        <mapping resource="com/andrew/model/Book.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

HibernateUtil.java

package com.andrew.util;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtil {
    private static final SessionFactory sessionFactory = buildSessionFactory();
    private static SessionFactory buildSessionFactory() {
        // 1. 实例化配置文件
        Configuration configuration = new Configuration().configure();
        // 2. 实例化服务登记
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();
        // 3. 获取Session工厂
        return configuration.buildSessionFactory(serviceRegistry);
    }
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

Book.java

package com.andrew.model;
import java.sql.Blob;
import java.util.Date;
public class Book {
    private int id;
    private String bookName; // 图书名称
    private float price; // 图书价格
    private boolean specialPrice; // 是否是特价
    private Date publishDate; // 发布日期
    private String author; // 作者
    private String introduction; // 简介
    private Blob bookPic; // 图书图片
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getBookName() {
        return bookName;
    }
    public void setBookName(String bookName) {
        this.bookName = bookName;
    }
    public float getPrice() {
        return price;
    }
    public void setPrice(float price) {
        this.price = price;
    }
    public boolean isSpecialPrice() {
        return specialPrice;
    }
    public void setSpecialPrice(boolean specialPrice) {
        this.specialPrice = specialPrice;
    }
    public Date getPublishDate() {
        return publishDate;
    }
    public void setPublishDate(Date publishDate) {
        this.publishDate = publishDate;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public String getIntroduction() {
        return introduction;
    }
    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }
    public Blob getBookPic() {
        return bookPic;
    }
    public void setBookPic(Blob bookPic) {
        this.bookPic = bookPic;
    }
}

Book.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.andrew.model">
    <class name="Book" table="t_book">
        <id name="id" column="bookId">
            <generator class="native"></generator>
        </id>
        <property name="bookName" column="bookName" length="40"></property>
        <property name="price" column="price" type="float"></property>
        <property name="specialPrice" column="specialPrice" type="boolean"></property>
        <property name="publishDate" column="publishDate" type="date"></property>
        <property name="author" column="author" length="20"></property>
        <property name="introduction" column="introduction" type="text"></property>
        <property name="bookPic" column="bookPic" type="blob"></property>
    </class>
</hibernate-mapping>

BookTest.java

package com.andrew.service;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Blob;
import java.text.SimpleDateFormat;
import org.hibernate.LobHelper;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import com.andrew.model.Book;
import com.andrew.util.HibernateUtil;
public class BookTest {
    public static void main(String[] args) throws Exception {
        SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession(); // 1. 生成一个session
        session.beginTransaction(); // 2. 开启事务
        
        Book book = new Book();
        book.setBookName("java编程思想");
        book.setPrice(100);
        book.setSpecialPrice(true);
        book.setPublishDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-1-1"));
        book.setAuthor("埃克尔");
        book.setIntroduction("简介...");
        
        LobHelper lobHelper = session.getLobHelper();
        InputStream in = new FileInputStream("e://java编程思想.jpg");
        Blob bookPic = lobHelper.createBlob(in, in.available());
        book.setBookPic(bookPic);
        session.save(book);
        
        session.getTransaction().commit(); // 3. 提交事务
        session.close(); // 4. 关闭session
    }
}

运行结果:
Hibernate: insert into t_book (bookName, price, specialPrice, publishDate, author, introduction, bookPic) values (?, ?, ?, ?, ?, ?, ?)


2. 集合类型映射

新建项目Hibernate06-02

hibernate.cfg.xml

<?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>
        <!-- 数据库连接设置 -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/hibernate4</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>
        <!-- 方言 -->
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <!-- 控制台显示SQL -->
        <property name="show_sql">true</property>
        <!-- 自动更新表结构 -->
        <property name="hbm2ddl.auto">update</property>
        <!-- Mapper -->
        <mapping resource="com/andrew/model/Student.hbm.xml"/>
        <mapping resource="com/andrew/model/Student2.hbm.xml"/>
        <mapping resource="com/andrew/model/Student3.hbm.xml"/>
        <mapping resource="com/andrew/model/Student4.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

HibernateUtil.java

package com.andrew.util;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtil {
    private static final SessionFactory sessionFactory = buildSessionFactory();
    private static SessionFactory buildSessionFactory() {
        // 1. 实例化配置文件
        Configuration configuration = new Configuration().configure();
        // 2. 实例化服务登记
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();
        // 3. 获取Session工厂
        return configuration.buildSessionFactory(serviceRegistry);
    }
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

StudentTest.java

package com.andrew.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.andrew.model.Student;
import com.andrew.model.Student2;
import com.andrew.model.Student3;
import com.andrew.model.Student4;
import com.andrew.util.HibernateUtil;
public class StudentTest {
    private SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
    private Session session;
    @Before
    public void setUp() throws Exception {
        session = sessionFactory.openSession(); // 1. 生成一个session
        session.beginTransaction(); // 2. 开启事务
    }
    @After
    public void tearDown() throws Exception {
        session.getTransaction().commit(); // 3. 提交事务
        session.close(); // 4. 关闭session
    }
}


2.1) Set无序 元素不可重复

Student.java

package com.andrew.model;
import java.util.Set;
public class Student {
    private long id;
    private String name;
    private Set<String> images;
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Set<String> getImages() {
        return images;
    }
    public void setImages(Set<String> images) {
        this.images = images;
    }
}

Student.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.andrew.model">
    <class name="Student" table="t_student">
        <id name="id" column="stuId">
            <generator class="native"></generator>
        </id>
        <property name="name" column="stuName"></property>
        <set name="images" table="t_image">
            <key column="studentId"></key>
            <element column="imageName" type="string"></element>
        </set>
    </class>
</hibernate-mapping>

StudentTest.java

@Test
public void testSetSave() {
    Set<String> imageSet = new HashSet<String>();
    imageSet.add("image1.png");
    imageSet.add("image2.png");
    imageSet.add("image3.png");
    imageSet.add("image3.png");
    Student s1 = new Student();
    s1.setImages(imageSet);
    session.save(s1);
}
@Test
public void testSetFetch() {
    Student student = (Student) session.get(Student.class, Long.valueOf(1));
    Iterator it = student.getImages().iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

运行结果:
Hibernate: insert into t_student (stuName) values (?)
Hibernate: insert into t_image (studentId, imageName) values (?, ?)
Hibernate: insert into t_image (studentId, imageName) values (?, ?)
Hibernate: insert into t_image (studentId, imageName) values (?, ?)
数据库:
t_student
1    NULL
t_image
1    image2.png
1    image1.png
1    image3.png
运行结果:
Hibernate: select student0_.stuId as stuId1_4_0_, student0_.stuName as stuName2_4_0_ from t_student student0_ where student0_.stuId=?
Hibernate: select images0_.studentId as studentI1_4_0_, images0_.imageName as imageNam2_0_0_ from t_image images0_ where images0_.studentId=?
image2.png
image1.png
image3.png


2.2) List有序 元素可重复

Student2.java

package com.andrew.model;
import java.util.List;
public class Student2 {
    private long id;
    private String name;
    private List<String> images;
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public List<String> getImages() {
        return images;
    }
    public void setImages(List<String> images) {
        this.images = images;
    }
}

Student2.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.andrew.model">
    <class name="Student2" table="t_student">
        <id name="id" column="stuId">
            <generator class="native"></generator>
        </id>
        <property name="name" column="stuName"></property>
        <list name="images" table="t_image2">
            <key column="studentId"></key>
            <list-index column="imageIndex"></list-index>
            <element column="imageName" type="string"></element>
        </list>
    </class>
</hibernate-mapping>

StudentTest.java

@Test
public void testListSave() {
    List<String> imageList = new ArrayList<String>();
    imageList.add("image1.png");
    imageList.add("image2.png");
    imageList.add("image3.png");
    imageList.add("image3.png");
    Student2 s2 = new Student2();
    s2.setImages(imageList);
    session.save(s2);
}
@Test
public void testListFetch() {
    Student2 student2 = (Student2) session.get(Student2.class, Long.valueOf(1));
    Iterator it = student2.getImages().iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

运行结果:
Hibernate: insert into t_student (stuName) values (?)
Hibernate: insert into t_image2 (studentId, imageIndex, imageName) values (?, ?, ?)
Hibernate: insert into t_image2 (studentId, imageIndex, imageName) values (?, ?, ?)
Hibernate: insert into t_image2 (studentId, imageIndex, imageName) values (?, ?, ?)
Hibernate: insert into t_image2 (studentId, imageIndex, imageName) values (?, ?, ?)
数据库:
t_student
1    NULL
t_image2
1    image1.png    0
1    image2.png    1
1    image3.png    2
1    image4.png    3
运行结果:
Hibernate: select student2x0_.stuId as stuId1_4_0_, student2x0_.stuName as stuName2_4_0_ from t_student student2x0_ where student2x0_.stuId=?
Hibernate: select images0_.studentId as studentI1_4_0_, images0_.imageName as imageNam2_1_0_, images0_.imageIndex as imageInd3_0_ from t_image2 images0_ where images0_.studentId=?
image1.png
image2.png
image3.png
image3.png


2.3) Bag无序 元素可重复

Student3.java

package com.andrew.model;
import java.util.List;
public class Student3 {
    private long id;
    private String name;
    private List<String> images;
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public List<String> getImages() {
        return images;
    }
    public void setImages(List<String> images) {
        this.images = images;
    }
}

Student3.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.andrew.model">
    <class name="Student3" table="t_student">
        <id name="id" column="stuId">
            <generator class="native"></generator>
        </id>
        <property name="name" column="stuName"></property>
        <idbag name="images" table="t_image3">
            <collection-id type="long" column="imageId">
                <generator class="increment"></generator>
            </collection-id>
            <key column="studentId"></key>
            <element column="imageName" type="string"></element>
        </idbag>
    </class>
</hibernate-mapping>

StudentTest.java

@Test
public void testBagSave() {
    List<String> imageList = new ArrayList<String>();
    imageList.add("image1.png");
    imageList.add("image2.png");
    imageList.add("image3.png");
    imageList.add("image3.png");
    Student3 s3 = new Student3();
    s3.setImages(imageList);
    session.save(s3);
}
@Test
public void testBagFetch() {
    Student3 student3 = (Student3) session.get(Student3.class, Long.valueOf(1));
    Iterator it = student3.getImages().iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

运行结果:
Hibernate: insert into t_student (stuName) values (?)
Hibernate: select max(imageId) from t_image3
Hibernate: insert into t_image3 (studentId, imageId, imageName) values (?, ?, ?)
Hibernate: insert into t_image3 (studentId, imageId, imageName) values (?, ?, ?)
Hibernate: insert into t_image3 (studentId, imageId, imageName) values (?, ?, ?)
Hibernate: insert into t_image3 (studentId, imageId, imageName) values (?, ?, ?)
数据库:
t_student
1    NULL
t_image3
1    image1.png    1
1    image2.png    2
1    image3.png    3
1    image4.png    4
运行结果:
Hibernate: select student3x0_.stuId as stuId1_4_0_, student3x0_.stuName as stuName2_4_0_ from t_student student3x0_ where student3x0_.stuId=?
Hibernate: select images0_.studentId as studentI1_4_0_, images0_.imageName as imageNam2_2_0_, images0_.imageId as imageId3_0_ from t_image3 images0_ where images0_.studentId=?
image1.png
image2.png
image3.png
image3.png


2.4) Map键值对

Student4.java

package com.andrew.model;
import java.util.Map;
public class Student4 {
    private long id;
    private String name;
    private Map<String, String> images;
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Map<String, String> getImages() {
        return images;
    }
    public void setImages(Map<String, String> images) {
        this.images = images;
    }
}

Student4.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.andrew.model">
    <class name="Student4" table="t_student">
        <id name="id" column="stuId">
            <generator class="native"></generator>
        </id>
        <property name="name" column="stuName"></property>
        <map name="images" table="t_image4">
            <key column="studentId"></key>
            <map-key column="imageKey" type="string"></map-key>
            <element column="imageName" type="string"></element>
        </map>
    </class>
</hibernate-mapping>

StudentTest.java

@Test
public void testMapSave() {
    Map<String, String> imageMap = new HashMap<String, String>();
    imageMap.put("i1", "image1.png");
    imageMap.put("i2", "image2.png");
    imageMap.put("i3", "image3.png");
    imageMap.put("i4", "image4.png");
    Student4 s4 = new Student4();
    s4.setImages(imageMap);
    session.save(s4);
}
@Test
public void testMapFetch() {
    Student4 student4 = (Student4) session.get(Student4.class, Long.valueOf(1));
    Map<String, String> imageMap = student4.getImages();
    Set keys = imageMap.keySet();
    Iterator it = keys.iterator();
    while (it.hasNext()) {
        String key = (String) it.next();
        System.out.println(key + ":" + imageMap.get(key));
    }
}

运行结果:
Hibernate: insert into t_student (stuName) values (?)
Hibernate: insert into t_image4 (studentId, imageKey, imageName) values (?, ?, ?)
Hibernate: insert into t_image4 (studentId, imageKey, imageName) values (?, ?, ?)
Hibernate: insert into t_image4 (studentId, imageKey, imageName) values (?, ?, ?)
Hibernate: insert into t_image4 (studentId, imageKey, imageName) values (?, ?, ?)
数据库:
t_student
1    NULL
t_image4
1    image1.png    i1
1    image2.png    i2
1    image3.png    i3
1    image4.png    i4
运行结果:
Hibernate: select student4x0_.stuId as stuId1_4_0_, student4x0_.stuName as stuName2_4_0_ from t_student student4x0_ where student4x0_.stuId=?
Hibernate: select images0_.studentId as studentI1_4_0_, images0_.imageName as imageNam2_3_0_, images0_.imageKey as imageKey3_0_ from t_image4 images0_ where images0_.studentId=?
i4:image4.png
i3:image3.png
i2:image2.png
i1:image1.png
分享到:
评论

相关推荐

    Hibernate 映射类型与Java 类型对照

    理解Hibernate映射类型与Java类型的对应关系对于有效地使用Hibernate至关重要。 首先,我们来看一下基本数据类型的映射。`integer`对应Java中的`int`或`Integer`,在SQL中映射为`INTEGER`类型;`long`对应`long`或`...

    hibernate映射类型.doc

    以下是一些常见的Hibernate映射类型及其对应的Java和SQL类型: 1. `Integer` 或 `java.lang.Integer`: 映射到标准SQL类型的 `Integer` (Oracle的 `number`)。 2. `Long` 或 `java.lang.Long`: 映射到 `BigInt` ...

    JAVA数据类型与Hibernate的类型映射

    对于数组和集合,如List、Set、Map等,Hibernate提供了ListType、SetType、MapType等映射类型,可以根据实际需求选择。 此外,自定义对象的映射是Hibernate映射中的一个重要部分。通过在实体类上使用@Entity注解,...

    hibernate映射枚举类型

    Hibernate,作为Java中广泛使用的对象关系映射(ORM)框架,提供了一种优雅的方式来映射枚举类型到数据库。本文将深入探讨Hibernate如何映射枚举类型,并给出实际应用示例。 ### Hibernate枚举映射方式 #### 1. `@...

    生成hibernate映射文件工具

    hibernate映射文件是Java开发中用于对象关系映射(ORM)的重要组成部分,它将数据库表与Java类之间的关系进行定义,使得开发者无需编写大量的SQL语句,就能实现对数据库的操作。`生成hibernate映射文件工具`是为了...

    hibernate映射和查询

    **hibernate映射与查询** Hibernate 是一个流行的 Java 应用程序开发框架,它提供了一个持久层解决方案,简化了数据库操作。对于初学者来说,理解 Hibernate 的映射和查询机制是至关重要的,因为它们构成了 ...

    Java数据类型,Hibernate数据类型,标准sql数据类型之间的对应表

    总而言之,Java数据类型、Hibernate映射类型和SQL数据类型之间的对应关系是Java开发者尤其是进行数据库交互的开发者必须掌握的基础知识。通过深入理解并熟练运用这些映射规则,我们可以更好地实现Java应用与数据库...

    java根据实体类生成Hibernate映射文件

    首先,我们需要了解Hibernate映射文件的基本结构。通常,一个映射文件以`.hbm.xml`为扩展名,它使用XML格式来描述Java类和数据库表的对应关系。映射文件包含了类名、表名、字段及其数据类型等信息。例如: ```xml ...

    Hibernate映射笔记

    ### Hibernate映射笔记详解 #### Hibernate映射文件与配置关系 Hibernate映射是ORM(对象关系映射)框架中的一项关键技术,它允许开发者在数据库表和Java对象之间建立映射关系,从而简化了数据访问层的开发工作。...

    常用 Hibernate 映射配置说明.doc

    ### 常用Hibernate映射配置详解 #### 1. hibernate-mapping节点解析 `hibernate-mapping`节点是Hibernate映射文件中的顶级节点,用于定义一系列配置选项,控制整个映射文件的行为和映射规则。这些配置包括数据库...

    java hibernate 数据库 类型对比

    在使用Hibernate时,我们需要将Java对象的属性映射到数据库中的列,这就涉及到Java类型与Hibernate映射类型以及标准SQL类型之间的对比。以下是对这些类型的详细解析: 1. **整数类型**: - Java中的`int`或`...

    hibernate映射Oracle中LONG类型

    "hibernate映射Oracle中LONG类型" Hibernate 框架映射 Oracle 中的 LONG 类型字段是一种复杂的技术问题。Oracle 中的 LONG 类型字段是一种特殊的数据类型,用于存储可变长字符串,最大长度限制是 2GB。这与 Java ...

    Hibernate数据类型映射及ID

    标题:“Hibernate数据类型映射及ID” 描述:“Hibernate与各数据库数据类型的映射” ### Hibernate数据类型映射 Hibernate作为一款流行的Java持久层框架,它提供了丰富的数据类型映射功能,使得开发者能够更加...

    Hibernate映射配置实例大全(详细总结)

    "Hibernate映射配置实例大全"是一个全面深入的资源,旨在帮助开发者理解和掌握如何有效地配置Hibernate以实现对象关系映射(ORM)。在这个文档中,我们将探讨各种关键的映射配置方法,以及相关的实例。 首先,我们...

    hibernate映射文件生成数据库

    Hibernate映射文件,通常以`.hbm.xml`为扩展名,是Hibernate用来定义Java类与数据库表之间关系的配置文件。它包含了关于实体类与数据库表的字段对应、主键生成策略、关联关系等信息。通过这些映射文件,Hibernate...

    用Hibernate映射继承关系

    ### 用Hibernate映射继承关系 #### 14.1 继承关系树的每个具体类对应一个表 在Hibernate中映射继承关系时,一种常见的策略是将继承关系树的每个具体类映射到单独的数据库表中。这种方法称为**表/类映射**(Table/...

    Hibernate映射实例

    多对多关系是最复杂的映射类型,例如学生可以选择多门课程,课程也可以被多个学生选择。在Hibernate中,使用`@ManyToMany`注解处理。多对多关系通常需要一个中间表来存储双方的关联信息,这个中间表可以通过`@Join...

    用MyEclipse自动生成hibernate映射文件和实体类

    3. **逆向工程(Hibernate Reverse Engineering)**:选中要映射的数据库表,右键选择`Hibernate Reverse Engineering`,这是MyEclipse提供的将数据库表转换为Hibernate映射文件和实体类的工具。 4. **配置生成选项...

    Hibernate映射文件主键的生成

    本篇文章将详细讲解Hibernate映射文件中关于主键生成的各种策略及其配置,帮助开发者更好地理解和使用。 首先,主键(Primary Key)是数据库表中用于唯一标识一条记录的字段,其值在表中必须是唯一的,并且通常不...

Global site tag (gtag.js) - Google Analytics