只要在你的工程里导入你需要的包!hibernate\lib下面的几个jar,除了这些还有就是外面的哪个 hibernate.jar别忘了!

解决方案 »

  1.   

    已经导入jar包了,具体怎么操作呢?谢谢回答!
      

  2.   

    hibernate是一种对JDBC的一中轻量级的封装,所以你用的时候不用太在意,你可以把他当成是一种jdbc, 只是是一种为了解决持久化的一种解决方案.
    一般一个hibernate的demo包括如下内容;
    首先,你的表结构,你的表的怎么设计,比如Customer,里面有多少字段
    /*
     * Created Thu Dec 23 16:31:55 CST 2004 by MyEclipse Hibernate Tool.
     */import java.io.Serializable;/**
     * A class that represents a row in the 'customer' table. 
     * This class may be customized as it is never re-generated 
     * after being created.
     */
    public class Customer
        extends AbstractCustomer
        implements Serializable
    {
        /**
         * Simple constructor of Customer instances.
         */
        public Customer()
        {
        }    /**
         * Constructor of Customer instances given a simple primary key.
         * @param cid
         */
        public Customer(java.lang.Integer cid)
        {
            super(cid);
        }    /* Add customized code below */}那么你要建立相应的PO,说白了就是一个class注意你定义的属性要和你的表匹配.
    还有就是需要一个Customer.hbm.xml用来说明你的表和类之间的结构关系,比如:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
                                "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
                                "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" ><!-- DO NOT EDIT: This is a generated file that is synchronized -->
    <!-- by MyEclipse Hibernate tool integration.                   -->
    <!-- Created Thu Dec 23 16:31:54 CST 2004                         -->
    <hibernate-mapping>
        <class name="Customer" table="customer">
            <id name="cid" column="CID" type="java.lang.Integer">
                <generator class="increment"/>
            </id>
             <property name="username" column="USERNAME" type="java.lang.String"  not-null="true" />
            <property name="password" column="PASSWORD" type="java.lang.String" />
        </class>
        </hibernate-mapping>
    最后一个hibernate.cfg.xml:
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
              "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
              "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"><!-- DO NOT EDIT: This is a generated file that is synchronized -->
    <!-- by MyEclipse Hibernate tool integration.                   -->
    <hibernate-configuration>    <session-factory>
            <!-- properties -->
            <property name="connection.username">root</property>
            <property name="connection.url">jdbc:mysql://localhost/test</property>
            <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
            <property name="connection.password">root</property>
            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>        <!-- mapping files -->
            <mapping resource="Customer.hbm.xml"/>
            <mapping resource="Cat.hbm.xml"/>
            <mapping resource="Item.hbm.xml"/>    </session-factory></hibernate-configuration>