Alex Rivera | Logout

How to make Hibernate not drop tables

Asked 2011-07-07T13:34:14.453
11

I am using hibernate and whenever I try to add a record it drops the table and adds it again. It never uses the existing table and make changes on that.

This is the relevant part of my hibernate.cfg.xml:

<hibernate-configuration>
<session-factory>
  <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
  <property name="hibernate.connection.url">jdbc:derby://localhost:1527/sample</property>
  <property name="hibernate.connection.username">user</property>
  <property name="hibernate.connection.password">password</property>
  <property name="hibernate.connection.pool_size">10</property>
  <property name="show_sql">true</property>
  <property name="dialect">org.hibernate.dialect.DerbyDialect</property>
  <property name="hibernate.hbm2ddl.auto">update</property>
  <property name = "current_session_context_class">thread</property>
  <!-- Mapping the entities -->
<mapping class="inputDetails.Table1"/>
<mapping class="inputDetails.Table2"/>


  <!--mapping resource="contact.hbm.xml"/-->
</session-factory>
</hibernate-configuration>

This is how I save data:

SessionFactory factory = new Configuration().configure().buildSessionFactory();
    Session session = factory.getCurrentSession();
    session.beginTransaction();
//...
session.save(newrecord)
session.getTransaction().commit();
Edit
Report

1 Answer

1

Hope this can help you

AnnotationConfiguration config = new AnnotationConfiguration();

config.addAnnotatedClass(Employee.class);
config.configure("hibernate.cfg.xml");
new SchemaExport(config).drop(false, false);
answered 2011-12-24T17:52:06.907

Your Answer