public class Cat {    private String id;
    private String name;
    private char sex;
    private float weight;    public Cat() {
    }    public String getId() {
        return id;
    }    public void setId(String id) {
        this.id = id;
    }    public String getName() {
        return name;
    }    public void setName(String name) {
        this.name = name;
    }    public char getSex() {
        return sex;
    }    public void setSex(char sex) {
        this.sex = sex;
    }    public float getWeight() {
        return weight;
    }    public void setWeight(float weight) {
        this.weight = weight;
    }    public String toString() {
        String strCat = new StringBuffer()
            .append(this.getId()).append(", ")
            .append(this.getName()).append(", ")
            .append(this.getSex()).append(", ")
            .append(this.getWeight())
            .toString();        return strCat;
    }
}

解决方案 »

  1.   

    public class HibernateUtil {    private static final SessionFactory sessionFactory;    static {
            try {
                sessionFactory = new Configuration().configure().buildSessionFactory();
            } catch (HibernateException ex) {
                throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
            }
        }    public static final ThreadLocal session = new ThreadLocal();    public static Session currentSession() throws HibernateException {
            Session s = (Session) session.get();
            // Open a new Session, if this Thread has none yet
            if (s == null) {
                s = sessionFactory.openSession();
                session.set(s);
            }
            return s;
        }    public static void closeSession() throws HibernateException {
            Session s = (Session) session.get();
            session.set(null);
            if (s != null)
                s.close();
        }
    }
      

  2.   

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping>    <class name="com.xanada.po.Cat" table="CAT">        <id name="id" type="string" unsaved-value="null" >
                <column name="CAT_ID" sql-type="varchar(20)" not-null="true"/>
                <generator class="uuid.hex"/>
            </id>        <property name="name">
                <column name="NAME" sql-type="varchar(20)" not-null="true"/>
            </property>        <property name="sex"/>        <property name="weight"/>    </class></hibernate-mapping>
      

  3.   

    也可能是你的sessionFacotry没有写好!也可能是你的hibernate.cfg.xml文件有问题!