精典Hibernate 学习笔记1代码

1.用Java应用中的属性文件!!

 hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/SAMPLEDB
hibernate.connection.username=root
hibernate.connection.password=1234
hibernate.show_sql=true

 

 

2.HIBERNATE 持久类!

package mypack;
import java.io.Serializable;
import java.sql.Date;
import java.sql.Timestamp;

public class Customer implements Serializable {
  private Long id;
  private String name;
  private String email;
  private String password;
  private int phone;
  private String address;
  private char sex;
  private boolean married;
  private String description;
  private byte[] image;
  private Date birthday;
  private Timestamp registeredTime;

  public Customer(){}

  public Long getId(){
    return id;
  }

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

  public String getName(){
    return name;
  }

  public void setName(String name){
    this.name=name;
  }

  public String getEmail(){
    return email;
  }

  public void setEmail(String email){
    this.email =email ;
  }

  public String getPassword(){
    return password;
  }

  public void setPassword(String password){
      this.password =password ;
  }

  public int getPhone(){
    return phone;
  }

  public void setPhone(int phone){
    this.phone =phone ;
  }

  public String getAddress(){
    return address;
  }

  public void setAddress(String address){
    this.address =address ;
  }
  public char getSex(){
    return sex;
  }

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

  public boolean isMarried(){
    return married;
  }

  public void setMarried(boolean married){
    this.married =married ;
  }

  public String getDescription(){
      return description;
  }

  public void setDescription(String description){
      this.description =description ;
  }

  public byte[] getImage() {
        return this.image;
  }

  public void setImage(byte[] image) {
        this.image = image;
  }

  public Date getBirthday() {
        return this.birthday;
  }

  public void setBirthday(Date birthday) {
        this.birthday = birthday;
  }

  public Timestamp getRegisteredTime() {
        return this.registeredTime;
  }

  public void setRegisteredTime(Timestamp registeredTime) {
        this.registeredTime = registeredTime;
  }

}

 

3.HIBERNATE持久类配置

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
  <class name="mypack.Customer" table="CUSTOMERS">
    
 
    <id name="id" column="ID" type="long">
      <generator class="increment"/>
    </id>
    <property name="name"  column="NAME"  type="string" not-null="true" /> 
    <property name="email"     column="EMAIL"     type="string" not-null="true" />
    <property name="password"  column="PASSWORD"  type="string" not-null="true"/>
    <property name="phone"     column="PHONE"     type="int" />
    <property name="address"   column="ADDRESS"   type="string" />
    <property name="sex"       column="SEX"       type="character"/> 
    <property name="married"   column="IS_MARRIED"  type="boolean"/>     
    <property name="description"   column="DESCRIPTION"  type="text"/>     
    <property name="image"         column="IMAGE"        type="binary"/>
    <property name="birthday"      column="BIRTHDAY"     type="date"/>
    <property name="registeredTime" column="REGISTERED_TIME"  type="timestamp"/> 

  </class>

</hibernate-mapping>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

w2512149

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值