1 Reply Latest reply on Jun 29, 2012 8:26 PM by henk de boer

    H2 embedded in JBoss AS 7

    Olivier Olivier Newbie



      I am currently trying to reuse set up a datasource pointing to the embedded H2 database. However, my objective is not to use the in-memory approach, but rather file bsed pêrsistency. My datasource is thus declared as follows:


      <datasources xmlns="http://www.jboss.org/ironjacamar/schema"


         xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">


         <datasource jndi-name="java:jboss/datasources/FesDS" pool-name="fes" enabled="true" use-java-context="true">










      A persistence.xml file points to that datasource.


      I have declared a bean as follows:


      public class FesService {
                private Logger logger;
                private EntityManager em;
                public String getTimestamp() {
                          DateFormat df = DateFormat.getDateTimeInstance();
                          Date now = Calendar.getInstance().getTime();
                          return df.format(now);
                public List<Entry> addEntry(int value) {
                          Entry entry = new Entry();
                          logger.info("persisted: " + entry);
                          return Collections.singletonList(entry);
                public List<Entry> getEntries() {
                          Query q = em.createQuery("select e from Entry e", Entry.class);
                          List<Entry> entries = q.getResultList();
                          return entries;


      It works pretty well. I can see the teh 3 H2 files created in the directory designated by the datasource. I see the statement begin issued, and I can create and retrieve data.

      What does not work is that if I restart the server, no durability is ensured, like if in-memory was used. I have set up the H2 web console, and I do not see any data persisted into the H2 database.

      Is the H2 database coming with Jboss AS7 only limited to in-memory database?






      PS: using JBoss AS 7.1.1.Final