1

I am using Spring Data jpa with Hibernate and Spring Data Redis and storing in MySQL database. Whenever I restart my application the existing data gets vanished.

Is there any properties that need be specified in application.properties or something else so that at the time of restarting application the data will not be vanished?

# jdbc.X
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ES?createDatabaseIfNotExist=true
jdbc.user=root
jdbc.pass=root


#hibernate.X
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=create-drop
halfer
  • 19,824
  • 17
  • 99
  • 186
Mohan.V
  • 141
  • 1
  • 1
  • 10
  • 3
    what do you think hibernate.hbm2ddl.auto=create-drop means? :) – slipperyseal Mar 17 '17 at 02:47
  • see: http://stackoverflow.com/questions/438146/hibernate-hbm2ddl-auto-possible-values-and-what-they-do/1689769 – slipperyseal Mar 17 '17 at 02:50
  • create-drop is good for running test suites where you want a new fresh database and for it to go away afterwards. but there are other options you can select to create and update but not delete. – slipperyseal Mar 17 '17 at 02:52
  • @SlipperySeal, why don't you put it as an answer? – SergGr Mar 17 '17 at 03:14
  • when i made the first comment i didn't feel as though I was expert enough to give a complete answer. then i started looking into the details. perhaps i should have then. – slipperyseal Mar 17 '17 at 03:43

1 Answers1

2

This is occurring because this property says to do so :)

hibernate.hbm2ddl.auto=create-drop

create-drop is good for running test suites where you want a new fresh database and for it to go away afterwards. but there are other options you can select to create and update but not delete.

I believe the common option to use is update. This will apply updates the the schema as changes occur but won't drop the schema.

hibernate.hbm2ddl.auto=update
slipperyseal
  • 2,728
  • 1
  • 13
  • 15