---
title: "使用MyEclipse进行hibernate的基本配置实现一对多"
author: "cakin24"
date: "2017-11-09T21:51:07Z"
tags: []
categories: ["编程语言"]
slug: "myeclipse-hibernate"
draft: false
lastmod: "2017-11-09T21:51:07Z"
id: 2399233
url: "https://cakin24.iteye.com/blog/2399233"
---

一 创建一个Java项目hibernate-one2many

 

二 添加Hibernate的Jar包

Hibernate的Jar包可从官网下载

添加完后的效果

![](http://dl2.iteye.com/upload/attachment/0127/7453/7ec9fb10-cf84-31d2-b9cd-9a37e34e988b.png)  
 

 

三 添加Mysql驱动Jar包

mysql-connector-java-5.1.30-bin.jar

 

四 创建一个hibernate.cfg.xml，并且编辑

&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;!DOCTYPE hibernate-configuration PUBLIC

                "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

                "[http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"](http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd%22);&gt;

&lt;hibernate-configuration&gt;

    &lt;session-factory&gt;

        &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;

            &lt;property name="hibernate.connection.password"&gt;root&lt;/property&gt;

            &lt;property name="hibernate.connection.driver\_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;

            &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://127.0.0.1:3306/imooc?useUnicode=true&amp;characterEncoding=UTF-8&lt;/property&gt;

            &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/property&gt;

        &lt;property name="show\_sql"&gt;true&lt;/property&gt;

            &lt;property name="format\_sql"&gt;true&lt;/property&gt;

            &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;

    &lt;/session-factory&gt;

&lt;/hibernate-configuration&gt;