JBoss AS 7.1.1 database erasing after restart

database, java, jboss7.x, xml

Solution

The datasource you're using is an in-memory h2 database. When your server goes down, this DB ceases to exist.

Switch to a real database instead.

For h2, the syntax would be: `jdbc:h2:~/mydb;DB_CLOSE_DELAY=-1` for a database located in ~/mydb. Use any path you like (you should have write access).

Problem

I'm using JBoss AS 7.1.1, and I have a problem with my database - it's being erased everytime I restart the server. Below you can see the content of my persistence file: ``` <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="wyklad2"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="update" /> <property name="hibernate.show_sql" value="false" /> </properties> </persistence-unit> </persistence> ``` DataSource configuration: ``` <subsystem xmlns="urn:jboss:domain:datasources:1.0"> <datasources> <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"> <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url> <driver>h2</driver> <security> <user-name>sa</user-name> <password>sa</password> </security> </datasource> <drivers> <driver name="h2" module="com.h2database.h2"> <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> </driver> </drivers> </datasources> </subsystem> ``` I will be very grateful for any clue that would help me fix this problem.

Original source