Skip to content
Advertisement

h2 database persists data but resets on application start

I have a basic test for an embedded database that I’m trying to get working for a java project. As it stands now I am able to save rows to the database with my entity repository object, and after the app finishes running, I can connect to the database with intellij and see those rows are still there. But then, if I comment out the save methods and run it again, when I check the database after it finishes, the database is empty.

Entity

JavaScript

Repository

JavaScript

main method

JavaScript

persistence.xml

JavaScript

hibernate.cfg.xml

JavaScript

I’m just following this tutorial here as a guide to just figure out how to get it all working. I can’t see what I’m doing wrong based on that.

Advertisement

Answer

You use:

JavaScript

As it is stated in the documentation:

create-drop

Drop the schema and recreate it on SessionFactory startup. Additionally, drop the schema on SessionFactory shutdown.

So, this is expected behaviour.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement