hibernate的環境配置

來源:互聯網
上載者:User

標籤: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的環境配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.