2 Replies Latest reply on Oct 13, 2014 8:34 PM by twittmin

    Configure H2 server mode database

    twittmin

      Hollo, I is testing the H2 database in wildfly 8 with the greeter example including in the QuickStart demos.  In the Web-INF/greeter-quickstart-ds.xml, I changed to "jdbc:h2:tcp://localhost/~/" from "jdbc:h2:mem:", then restart the server, it reports a "File Not Found" error. Should I make any other change in the settings?

       

      <datasource jndi-name="java:jboss/datasources/GreeterQuickstartDS"

              pool-name="greeter-quickstart" enabled="true" use-java-context="true">

              <connection-url>jdbc:h2:mem:greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>

              <driver>h2</driver>

              <security>

                  <user-name>sa</user-name>

                  <password>sa</password>

              </security>

          </datasource>

       

      I didn't change anything in the persistence.xml:

       

        <persistence-unit name="primary">

              <!-- If you are running in a production environment, add a managed

                  data source, this example data source is just for development and testing! -->

              <!-- The datasource is deployed as WEB-INF/greeter-quickstart-ds.xml,

                  you can find it in the source at src/main/webapp/WEB-INF/greeter-quickstart-ds.xml -->

              <jta-data-source>java:jboss/datasources/GreeterQuickstartDS</jta-data-source>

              <properties>

                  <!-- Properties for Hibernate -->

                  <property name="hibernate.hbm2ddl.auto" value="create-drop" />

                  <property name="hibernate.show_sql" value="false" />

              </properties>

          </persistence-unit>

       

      Thanks for any info and help.

        • 1. Re: Configure H2 server mode database
          ochaloup

          It rather seems that you haven't start the H2 database on the same place where you define the address put in wildfly configuration.

           

          An idea - maybe the address should be jdbc:h2:tcp://localhost/~/test (taken from h2 tutorial)?

          • 2. Re: Configure H2 server mode database
            twittmin

            This is the original datasource setting:

             

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

                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

                <!-- The datasource is bound into JNDI at this location. We reference

                    this in META-INF/persistence.xml -->

                <datasource jndi-name="java:jboss/datasources/GreeterQuickstartDS"

                    pool-name="greeter-quickstart" enabled="true" use-java-context="true">

                    <connection-url>jdbc:h2:mem:greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>

                    <driver>h2</driver>

                    <security>

                        <user-name>sa</user-name>

                        <password>sa</password>

                    </security>

                </datasource>

            </datasources>

             

            And I changed it to

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

                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

                <!-- The datasource is bound into JNDI at this location. We reference

                    this in META-INF/persistence.xml -->

                <datasource jndi-name="java:jboss/datasources/GreeterQuickstartDS"

                    pool-name="greeter-quickstart" enabled="true" use-java-context="true">

                    <connection-url>jdbc:h2:tcp://localhost/~/greeter-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>

                    <driver>h2</driver>

                    <security>

                        <user-name>sa</user-name>

                        <password>sa</password>

                    </security>

                </datasource>

            </datasources>

             

            Then I got a "File not found" error.  Do I also need to change anything in persistence.xml? I didn't. And this is the file:

             

            <persistence version="2.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_2_0.xsd">

                <persistence-unit name="primary">

                    <!-- If you are running in a production environment, add a managed

                        data source, this example data source is just for development and testing! -->

                    <!-- The datasource is deployed as WEB-INF/greeter-quickstart-ds.xml,

                        you can find it in the source at src/main/webapp/WEB-INF/greeter-quickstart-ds.xml -->

                    <jta-data-source>java:jboss/datasources/GreeterQuickstartDS</jta-data-source>

                    <properties>

                        <!-- Properties for Hibernate -->

                        <property name="hibernate.hbm2ddl.auto" value="create-drop" />

                        <property name="hibernate.show_sql" value="false" />

                    </properties>

                </persistence-unit>

            </persistence>

             

            Thanks.