G Bisconcini
G Bisconcini

Reputation: 774

Jboss AS 7.1.1 Access/Query Embedded H2 Database

I'm trying to access my embedded h2 server and query. I can access, but the tables I have created don't appear on the Jboss H2 tool.

Here is my persistence.xml

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
    version="2.1">
    <persistence-unit name="primary">
        <jta-data-source>java:jboss/datasources/xxxDS</jta-data-source>
        <properties>
            <!-- For auto create tables on startup -->
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            <property name="hibernate.show_sql" value="false" />
        </properties>
    </persistence-unit>
</persistence>

xxx-ds.xml

<?xml version="1.0" encoding="UTF-8"?>
<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">

    <!--  start H2 DATABASE -->
    <datasource jndi-name="java:jboss/datasources/xxxDS"
        pool-name="xxx" enabled="true"
        use-java-context="true">
        <connection-url>jdbc:h2:mem:xxx;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>

accessing the H2 embedded database by the Jboss tool (see the test successful on the image): java -jar /opt/jboss/jboss-as-7.1.1.Final/modules/com/h2database/h2/main/h2-1.3.161.jar the screenshot

I can connect, but I cannot see the tables I've created in the application. I only see the h2 system tables. I cannot see my tables created

How can I see the tables my application is persisting?

Upvotes: 1

Views: 1796

Answers (1)

Guillermo
Guillermo

Reputation: 1533

You are using in-memory database so accessing from different JVM and class loader environment won't work.

As you are using Jboss 7 you can use the h2console quickstart to view the database content. Here is the project, it builds a war that you just have to deploy in <jboss_home>/(domain|standalone)/deployments.

Also take note that with the option create-drop for hibernate.hbm2ddl.auto will drop any database object when the applications is undelployed.

If you have chance to change the h2 database configuration, you could set its server mode. See this short tutorial to know how to do it fast :)

Upvotes: 2

Related Questions