If it is duplicate, my apology. I could not find an answer for my question.
I just start Hibernate. I have an issue is every time the program automatically delete the old shceme and creates new when it is running. For example, If I want to add records into database, I could not do it because the scheme will be recreate, so the histories will be deleted.
Here is my hbm.xml mapping file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 22-Oct-2013 1:39:31 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="net.ys.hibernate.Equip" table="EQUIP">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="native" />
        </id>
        <property name="dis" type="java.lang.String" column="dis" />
        <property name="ref" type="java.lang.String" column="ref" />
        <property name="type" type="java.lang.String" column="type" />
    </class>
</hibernate-mapping>
hibernate.cfg.xml configuration file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- hibernate dialect -->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">pw</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/explorer_DB?useUnicode=true&characterEncoding=GBK</property>
        <property name="hibernate.connection.username">username</property>
        <property name="hibernate.default_schema">explorer_DB</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <!-- Automatic schema creation(begin) -->
        <property name="hibernate.hbm2ddl.auto">create</property>
        <!-- Simple memory-only cache -->
        <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
        <!-- mapping files with external dependencies -->
        <mapping resource="net/ys/hibernate/Equip.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
And addEquip method:
public Integer addEquip(String dis, String ref, String type){
        Session session = sessionFactory.openSession();
        currentSession = sessionFactory.getCurrentSession();
        Transaction tx = null;
        Integer equipID = null;
        try {
            tx = currentSession.beginTransaction(); //start a transaction
            Equip equip = new Equip(dis,ref,type);
            equipID = (Integer)currentSession.save(equip);
            tx.commit();
        } catch (HibernateException e) {
            if(tx!=null) tx.rollback();
            e.printStackTrace();
        } finally {
            session.close();
        }
        return equipID;
    }
}
could someone help me to solve this issue? I just don't understand how to use getCurrentSession(), probably I am wrong in this point. Could you explain how hibernate works when we call getCurrentSession() for me? I really appreciate it.
Thank you so much
 
     
    