第一個hibernate檔案 xml配置方法

來源:互聯網
上載者:User

標籤:blog   http   io   使用   java   for   檔案   sp   資料   

package com.entity;public class User {private String username;private String password;private Integer id;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}}

User.java

java實體類

1·要求要有一個屬性叫做id的指向資料庫表上的主鍵 ,唯一標示一條記錄;

2·對屬性產生get,set方法

3·必須有一個無參構造方法

 

 

<?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="com.entity.User" table="t_user"><id name="id" type="java.lang.Integer"><column name="id" length="32"/><generator class="native"/></id><property name="username" type="java.lang.String"><column name="username"/></property><property name="password" type="java.lang.String"><column name="password"/></property></class></hibernate-mapping>

 user.hbm.xml

資料庫對應檔

 

有xml的對應檔的話就在cfg.xml中加上<mapping resource="com/entity/user.hbm.xml"/>這類

在實體類上打註解的話  就在cfg.xml中加上<mapping class="com.entity.User"/>

注意!!!對應檔是xml的話    路徑是用/間隔開的 

     在實體類上打註解的話   配置時使用.間隔開的 

第一個hibernate檔案 xml配置方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.