<1> AbstractUser

package com.xh.hibernate.vo;

import java.io.Serializable;

public abstract class AbstractUser implements Serializable {

    private int hashValue = 0;

    private java.lang.Integer id ;

    private java.lang.String firstname ;

    private java.lang.String lastname ;

    public AbstractUser() {

    }

    public AbstractUser(java.lang.Integer id) {

        this .setId(id);

    }

    public java.lang.Integer getId() {

        return id ;

    }

    public void setId(java.lang.Integer id) {

        this . hashValue = 0;

        this . id = id;

    }

    public java.lang.String getFirstname() {

        return this . firstname ;

    }

    public void setFirstname(java.lang.String firstname) {

        this . firstname = firstname;

    }

    public java.lang.String getLastname() {

        return this . lastname ;

    }

    public void setLastname(java.lang.String lastname) {

        this . lastname = lastname;

    }

    public boolean equals(Object rhs) {

       if (rhs == null )

           return false ;

       if (!(rhs instanceof User))

           return false ;

       User that = (User) rhs;

       if ( this .getId() == null || that.getId() == null )

           return false ;

        return ( this .getId().equals(that.getId()));

    }

    public int hashCode() {

       if ( this . hashValue == 0) {

           int result = 17;

           int idValue = this .getId() == null ? 0 : this .getId().hashCode();

           result = result * 37 + idValue;

           this . hashValue = result;

       }

        return this . hashValue ;

    }

}



<2> User

package com.xh.hibernate.vo;

import java.io.Serializable;

public class User extends AbstractUser implements Serializable {

    private static final long serialVersionUID = 7867396135472865699L;

    public User() {

    }

    public User(java.lang.Integer id) {

        super (id);

    }

}

 

<3> User.hbm.xml

<? xml version = "1.0" encoding = "GBK" ?>

<! DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

< hibernate-mapping package = "com.xh.hibernate.vo" >

    < class name = "User" table = "user_tab" >

       < id name = "id" column = "id" type = "integer" >

           < generator class = "increment" />

       </ id >

        < property name = "firstname" column = "firstname" type = "string"

           not-null = "true" />

        < property name = "lastname" column = "lastname" type = "string"

           not-null = "true" />

    </ class >

</ hibernate-mapping >