How to do crud operations on HSQLDB running in Fuse 6.2.1?

Solution Unverified - Updated -

Environment

  • Red Hat JBoss Fuse
    • 6.2.1

Issue

  • How can I get HSQLDB running in Fuse 6.2.1?
  • I have a persistence implementation that is working when I configure it to use the postgresql database underneath Hibernate.
  • I would like to experiment with HSQLDB.
  • I've configured HSQLDB in my persistence.xml file based on numerous web posts I've seen, and I believe I've included the hsqldb jar file in my bundle in the features file.
  • when I try to install my feature in fuse I get an error message that ultimately states: "Specified JDBC Driver org.hsqldb.jdbcDriver could not be loaded".

Resolution

  • Persistence in HSQLDB can be done in two ways one is as in memory hsql,second is file based hsql
  • Configure Datasource in Datasource bundle and expose it as a jndi service
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver"/>
        <property name="url" value="jdbc:hsqldb:mem:referenceindex;sql.syntax_pgs=true;hsqldb.sqllog=3"/>
        <property name="username" value="sa"/>
        <property name="password" value=""/>
    </bean>

    <!-- Expose DataSources as JNDI references -->
    <service ref="dataSource" interface="javax.sql.DataSource">
        <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/jpadatasource"/>
        </service-properties>
    </service>
  • Have hibernate dialect and properties configured in persistence.xml in another bundle
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name="jpa-repository" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>osgi:service/jdbc/jpadatasource</jta-data-source>
        <class>com.mycompany.test.jpa.model.BasicSystem</class>
        <properties>
            <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbc.JDBCDriver" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.cache.use_second_level_cache" value="false" />
        </properties>
    </persistence-unit>
  • Refer attached example for full configuration
  • To test the example first install jndi,hibernate features and install hsqldb.jar
features:install jndi
features:install hibernate
osgi:install -s wrap:file:/pathto/hsqldb.jar
  • Install datasource bundle
osgi:install -s mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_3
osgi:install -s  mvn:com.mycompany.esb.test/jpa-datasource/1.0.0-SNAPSHOT
  • install jpa-reproducer bundle
osgi:install -s mvn:com.mycompany.esb.test/jpa-reproducer/1.0.0-SNAPSHOT

Attachments

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments