1

Using hibernate4

SessionFactory factory = new Configuration().configure()
            .buildSessionFactory();
    Session session = factory.openSession();
    session.beginTransaction();
    //do some task
    session.getTransaction().commit();
    session.close();
    factory.close();

Using auto generated proprty

<property name="hibernate.hbm2ddl.auto">create-drop</property>

as you can see I am closing my session factory it drops all my tables after this code completed as I see on console. Is it the default behaviour

Ankit Katiyar
  • 2,631
  • 2
  • 20
  • 30

3 Answers3

1

This is expected behavior for the create-drop mode.

See this documentation for more information.

Additionally, see this article for more exposition on the values.

Community
  • 1
  • 1
Dave G
  • 9,639
  • 36
  • 41
1

That's the intention of the property create-drop.

Use create or update to keep your tables.

StuPointerException
  • 7,117
  • 5
  • 29
  • 54
0

change hbm2dll.auto property in your hibernate mapping to "update" to keep the changes you do in the database.

Darshan Lila
  • 5,772
  • 2
  • 24
  • 34