Configuring Liberty Profile to use H2 database

落花浮王杯 提交于 2019-12-11 05:49:41

问题


I have an embedded H2 database running that I have been connecting to as such: Browser H2 interface

This works exactly as desired. I'm using JPA/EJB/JSF to build an EAR that will run on Liberty Profile. I've configured Liberty Profile to work with several different databases in the past, but am having no luck with H2. My server.xml looks like this:

<!-- Enable features -->

<featureManager>
    <feature>ejbLite-3.1</feature>
    <feature>servlet-3.0</feature>
    <feature>localConnector-1.0</feature>
    <feature>managedBeans-1.0</feature>
    <feature>cdi-1.0</feature>
    <feature>jpa-2.0</feature>
    <feature>jaxrs-1.1</feature>
    <feature>jsf-2.0</feature>
    <feature>jaxws-2.2</feature>
</featureManager>
<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

<library description="XXXX" id="XXXX" name="XXXX">
    <fileset dir="${shared.resource.dir}/XXXX" includes="*.jar"/>
</library>



<dataSource type="javax.sql.DataSource" id="XXXX" jndiName="jdbc/XXXX">
        <jdbcDriver javax.sql.DataSource="org.h2.jdbcx.JdbcDataSource">
            <library>
                <fileset caseSensitive="false" dir="${shared.resource.dir}/XXXX"/>
            </library>
        </jdbcDriver>

     <properties password="gg" URL="jdbc:h2:~/XXXX" user="SA" databaseName="XXXXDB"/>
</dataSource>

<applicationMonitor updateTrigger="mbean"/>

This method never finds the database. I've also tried using 192.168.2.13:8087, but that gives

 org.apache.openjpa.persistence.PersistenceException: No suitable driver found for http://192.168.2.13:8087 DSRA0010E: SQL State = 08001, Error Code = 8,001
    at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:102)
    at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:603). 

I've spent a considerable amount of time searching google for the proper configuration, but have been unsuccessful. Any guidance would be greatly appreciated.

Thanks in advance.


回答1:


This is my working h2 configuration in the server.xml of the wlp:

<dataSource
    id="mydb"
    jndiName="jdbc/mydb"
    type="javax.sql.ConnectionPoolDataSource">
    <jdbcDriver
        javax.sql.ConnectionPoolDataSource="org.h2.jdbcx.JdbcDataSource"
        javax.sql.DataSource="org.h2.jdbcx.JdbcDataSource"
        javax.sql.XADataSource="org.h2.jdbcx.JdbcDataSource"
        libraryRef="SharedLibrary_H2"/>
    <properties
        URL="jdbc:h2:C:/Apps/db/h2/mydb.db;MV_STORE=FALSE;AUTO_SERVER=TRUE"
        databaseName="MY_DB"
        user="sa"
        password="sa" />
   </dataSource>

<library id="SharedLibrary_H2">
    <fileset dir="${shared.resource.dir}/h2" id="Fileset_H2"/>
</library>

The h2.jar must be available at:

C:\path\to\wlp\usr\shared\resources\h2\h2-1.4.187.jar

In the persistence unit of your peristence.xml:

<jta-data-source>jdbc/mydb</jta-data-source>



回答2:


The error you are receiving seems to indicate that OpenJPA can't determine which DBDictionary to use. When first initiating database connectivity, OpenJPA tries to determine the proper dictionary to use based on the connection's metadata. In this case, either a connection can't be established to the database (you should be able to verify this with the given url information for your database), or OpenJPA can't determine the database type based on the metadata. My guess is that it's the latter situation you are running into.

You can bypass this automatic dictionary detection by specifying the dictionary in your persistence.xml file. Try specifying this property and see what your results are.

<property name="openjpa.jdbc.DBDictionary" value="h2"/>

More detailed information can be found here: http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#ref_guide_dbsetup_dbsupport



来源:https://stackoverflow.com/questions/24353077/configuring-liberty-profile-to-use-h2-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!