欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解 hibernate mapping配置

 更新時(shí)間:2017年06月01日 14:12:01   作者:medtrib  
這篇文章主要介紹了,每個(gè)hibernate只會(huì)啟動(dòng)的時(shí)候引入一個(gè)文件,那就是:hibernate.cfg.xml mapping需要我們?cè)趆ibernate中引入, <mapping resource="com/hibernate/test/hibernate_IP.的相關(guān)資料,需要的朋友可以參考下

詳解 hibernate mapping配置

每個(gè)hibernate只會(huì)啟動(dòng)的時(shí)候引入一個(gè)文件,那就是:hibernate.cfg.xml

mapping需要我們?cè)趆ibernate中引入,

<mapping resource="com/hibernate/test/hibernate_IP.xml"/>
<mapping class="com.hibernate.test.Student"/>

代碼片段:

<?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.hibernate.test"> 

  <class name="IP_List" table="IP_LIST"> 
    <id name="ip" column="Ip"> 
<generator class="native"></generator> 
    </id> 
    <property name="Status" column="Status"></property> 
  </class> 

</hibernate-mapping>

class標(biāo)簽 對(duì)應(yīng)的name為Java實(shí)體類 table為表名;

id為主鍵  主鍵自增策略:<generator class="native"></generator>   native會(huì)根據(jù)不同數(shù)據(jù)庫 采取不同的自增策略

<property>標(biāo)簽對(duì)應(yīng)數(shù)據(jù)庫中的字段 column

package com.hibernate.test;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Student")
public class Student {
  private int id;
  private String name;

  /**
   * id
   * 
   * @return the id
   * @since CodingExample Ver(編碼范例查看) 1.0
   */
  @Id

    @GeneratedValue
  public int getId() {
    return id;
  }

  /**
   * 
   * @param id
   *      the id to set
   */
  public void setId(int id) {
    this.id = id;
  }

  /**
   * name
   * 
   * @return the name
   * @since CodingExample Ver(編碼范例查看) 1.0
   */

    @Column(name="name")
  public String getName() {
    return name;
  }

  /**
   * 
   * @param name
   *      the name to set
   */
  public void setName(String name) {
    this.name = name;
  }
}

實(shí)體類添加注解:@Entity 對(duì)應(yīng)的表為@Table

主鍵為@ID   自增策略配置:@GeneratedValue

@Column 注解對(duì)應(yīng)為數(shù)據(jù)庫中的字段

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論