码迷,mamicode.com
首页 > Web开发 > 详细

hibernate的环境配置

时间:2016-11-30 02:17:29      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:zab   导入   ted   javabean   dial   配置   bean   min   imp   

1,首先把跟Hibernate相关的jar包导入到lib目录下;

技术分享

 

2,写Javabean类

package chen.can.Dao;

public class TRegister implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
// Fields

private Integer id;
private String userName;
private String userPwd;
private String sex;
private Integer age;


// Constructors

/** default constructor */
  public TRegister() {
}

/** minimal constructor */
public TRegister(Integer id) {
  this.id = id;
}

/** full constructor */
public TRegister(Integer id, String userName, String userPwd, String sex, Integer age) {
  this.id = id;
  this.userName = userName;
  this.userPwd = userPwd;
  this.sex = sex;
  this.age = age;
}


// Property accessors

public Integer getId() {
  return this.id;
}

public void setId(Integer id) {
  this.id = id;
}

public String getUserName() {
  return this.userName;
}

public void setUserName(String userName) {
  this.userName = userName;
}

public String getUserPwd() {
  return this.userPwd;
}

public void setUserPwd(String userPwd) {
  this.userPwd = userPwd;
}

public String getSex() {
  return this.sex;
}

public void setSex(String sex) {
  this.sex = sex;
}

public Integer getAge() {
  return this.age;
}

public void setAge(Integer age) {
  this.age = age;
}
}

 

3,在这个javabean目录下写相同名字的   ×××.hbm.xml文件

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="chen.can.Dao.TRegister" table="t_register">//注意下,这里千万记得写javabean所在的目录
<id name="id" type="java.lang.Integer">
<column name="id" />
<!-- 我在MYSQL中并没有设置该字段递增,但在Hibernate中依然可以设置为递增 -->
<generator class="increment" />
</id>

<property name="userName" type="java.lang.String">
  <column name="userName" length="30" />
</property>
<property name="userPwd" type="java.lang.String">
  <column name="userPwd" length="30" />
</property>
<property name="sex" type="java.lang.String">
  <column name="sex" length="10" />
</property>
<property name="age" type="java.lang.Integer">
  <column name="age" />
</property>


</class>
</hibernate-mapping>

4,在src目录下写hibernate.cfg.xml

<?xml version=‘1.0‘ encoding=‘UTF-8‘?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 驱动程序名 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- 数据库名称 -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3305/login</property>
<!-- 用户名 -->
<property name="hibernate.connection.username">root</property>
<!-- 密码 -->
<property name="hibernate.connection.password">000000</property>
<property name="show_sql">true</property>
<mapping resource="chen/can/Dao/TRegister.hbm.xml" />

</session-factory>

</hibernate-configuration>

 

hibernate的环境配置

标签:zab   导入   ted   javabean   dial   配置   bean   min   imp   

原文地址:http://www.cnblogs.com/chencanjian/p/6115494.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!