0

In Hibernate if we set hbm2ddl.auto to create/create-drop , then it will delete the old schema and create the new schema when starts. It means, it will delete data also?.. My doubt is if it deletes every thing then how could we retrive the old data? (eg: user registration details) and what is the correct option should use in production environments?

Pls correct me, if I am wrong.

Rajesh G
  • 1
  • 1
  • 1

3 Answers3

1

It basically drops the managed entity tables (not all of them in the scheme) on shutdown and recreates them on startup back again. Means as per your question; yes data is dropped from the tables as well. It does not drop the the whole schema but only the entities in the entity manager.

Olgun Kaya
  • 2,519
  • 4
  • 32
  • 46
0

what is the correct option should use in production environments?

IMHO, the only valid option for production environements is validate. Everything else can cause potential risk of loosing data/breaking db schema due to misscofiguration, simple mistake or typo.

Use migrations tools for schema updates as they provide "version controll" over your schema allowing it to be tested before depoyment, and revert the changes.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • Hi, If i want to add new tables and new columns to existed tables in database, then hbm2ddl.auto=validate will suit (with the condition of dont touch the existed schema/tables/data?) – Rajesh G Jun 16 '17 at 07:03
  • Till you are not in production you can use update,in production use only validate. Update add new columns,tables,indexes dut not drop that you already have in it's not in mapping now – xyz Jun 16 '17 at 07:05
0

validate- existing schema

update- only update your schema once created

create- create schema every time.

Also here is a good explanation Hibernate hbm2ddl.auto possible values and what they do?

xyz
  • 5,228
  • 2
  • 26
  • 35