Ankit
Ankit

Reputation: 433

Database Issue in Spring MVC- HIbernate example

When I run the example

on my system with mvn tomcat:run command,

Data in mysql tables get's deleted.

So, I had to insert data every time I restart the application.

Upvotes: 0

Views: 438

Answers (1)

cdeszaq
cdeszaq

Reputation: 31280

Assuming you followed the tutorial from the linked page exactly, the reason the MySQL data is being removed each time the application starts can be found in the hibernate.cfg.xml file.

Specifically, it's these lines:

<!-- This will drop our existing database and re-create a new one.
      Existing data will be deleted! -->
    <property name="hbm2ddl.auto">create</property>

I don't remember what the other values are off the top of my head, but I believe validate will only check that your schema is correct but not change anything. update may also work.

Upvotes: 2

Related Questions