I\'m working with Hibernate. How can I configure my persistence.xml to have an H2 in-memory database?
My persistence.xml is:
You should set hibernate.hbm2ddl.auto property to "create" the first time you run your application, to create the tables
<property name="hibernate.hbm2ddl.auto" value="create" />
and then (if you don't want the tables to be recreated and emptied every time you start) set it to "validate".
<property name="hibernate.hbm2ddl.auto" value="validate" />
To create the schema automatically, add if-not-exists to your connection url like this:
<property name="hibernate.connection.url" value="jdbc:h2:~/<filename>;INIT=CREATE SCHEMA IF NOT EXISTS <schema_name>" />