Announcement Announcement Module
No announcement yet.
Spring Roo DB2 introspection fails Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Roo DB2 introspection fails

    I have been trying to reverse engineer tables in DB2.
    I did a mvn:install of the db2jcc driver jars but the introspection fails with the following

    addon search --requiresDescription "#jdbcdriver, " found no matches
    JDBC driver not available for ''

    Am I missing anything?


  • #2
    You will need to wrap the DB2 driver to make it compatible with OSGi for use in Roo. The DB2 driver is a licensed piece of software and we can't host OSGi versions of the driver in any public Maven repository. Alternatively, I assume you have a support contract with IBM, so perhaps you can approach them to supply you with an OSGi-wrapped driver. After all they are one of the OSGi founders.


    • #3
      Thanks Alan!
      One question though, to work with Spring Roo do all components have to be OSGi compatible?


      • #4
        Any component that needs to work in the Roo shell needs to be OSGi compliant.

        Obviously, Roo-generated user projects do not have such a dependency. Thus, while Roo can generate a project to use DB2 as its database when the application is spun up in a web container or in unit tests, to reverse engineer a DB2 database, Roo itself needs to use an OSGI-enabled DB2 driver.

        I have tried to OSGi-ify the driver from the DB2 community edition some time ago. There appears to be three jars required which made it tedious to do. I shall get back to it some time and at the very least provide the pom for our addon-creator to make the jars work.
        Last edited by Alan Stewart; Mar 29th, 2011, 10:39 PM.


        • #5
          Thanks Alan, that was helpful.


          • #6
            The pom.xml apparently needs only very little tweaking. A solution for a very similar problem with Oracle JDBC drivers is described here, and Alan's suggestion in that thread can be translated to db2 straightforwardly. Using the db2 driver in db2jcc4.jar from the DB2 Express C version 9.7.2, i followed the same procedure, adding this Import-Package element in the generated pom.xml:

            and one "osgi start -url <filename>" later DBRE was working.


            • #7
              Awesome... I'll give that a shot.


              • #8
                Using the db2 driver in db2jcc4.jar from the DB2 Express C version 9.7.2, i followed the same procedure, adding this Import-Package element in the generated pom.xml:
                Great stuff!
                Did you only require just the one jar? Can you post the full pom.xml for the wrapping? I will try it out and if OK, I will add it to the Roo wrapping directory.


                • #9
                  Sure, here you are:

                  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
                  <project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
                  	<description>This bundle wraps the standard Maven artifact: ${pkgArtifactId}-${pkgVersion}.</description>
                  			<id>Google Code</id>
                  						<Bundle-Vendor>${pkgVendor} (wrapped into an OSGi bundle by the Spring Roo project build system)</Bundle-Vendor>

                  The full procedure with db2jcc4.jar in the .m2 repository and a database named foo on localhost is:

                  1. Create 2 projects: wrapper and dbre.

                  2. In wrapper, start roo:

                  addon create wrapper --topLevelPackage --groupId --artifactId db2jcc4 --version 9.7.2 --vendorName IBM --licenseUrl
                  3. Edit the pom.xml to include the Import-Package line

                  4. mvn bundle:bundle

                  5. Copy the jar from wrapper/target to wrapper (i'm too lazy to figure out the correct --url file syntax). Start roo again:

                  osgi start --url
                  6. In dbre, start roo:

                  project --topLevelPackage com.example
                  persistence setup --provider HIBERNATE --database DB2 --hostName localhost --databaseName foo --userName foo --password bar
                  dependency remove --groupId --artifactId db2jcc --version 3.59.81
                  dependency add --groupId --artifactId db2jcc4 --version 9.7.2
                  database introspect --schema foo
                  database reverse engineer --schema foo
                  and that's it. As far as i can tell, only the db2jcc4.jar is required.


                  • #10
                    Thanks all for the helpful tips. I'm facing a similar issue, but can't get to a resolution.

                    The firm that I work for has an OSGi bundled version of the commercial DB2 drivers available internally, so I created a new Springroo project, and tried to load the OSGi driver.

                    The driver appears to have loaded.
                    START LEVEL 99
                       ID   State         Level  Name
                    [  65] [Active     ] [    1] Spring Roo - Shell (Eclipse Implementation) (1.1.0.RELEASE)
                    [  67] [Active     ] [    1] db2jcc (8.2.1)
                    [  69] [Active     ] [    1] license_cu (8.2.1)
                    But when I try to create a persistence setup I get an exception:

                    roo> persistence setup --provider HIBERNATE --database DB2 --hostName localhost --databaseName foo --userName foo --password bar
                    java.lang.IllegalStateException: Failed to convert 'DB2' to type JdbcDatabase for option 'database'
                    Any thoughts on what I'm missing here? Its driving me crazy!

                    Thanks in advance.


                    • #11
                      If you simply press TAB on the --database option in the persistence setup command you will see two options for DB2: DB2_400 and DB2_EXPRESS_C. There is no option for the string "DB2" itself


                      • #12
                        So I followed wallenborn direction but got an issue on Step 6

                        persistence setup --provider HIBERNATE --database DB2 --hostName localhost --databaseName foo --userName foo --password bar

                        As Alan pointed out you will get only two options for DB2 i.e DB2_400 and DB2_EXPRESS_C.
                        I went ahead to change DB2 in above command to DB2_400
                        This allowed me to get persistence.xml and file that get roo automatically generates. I manually went and changed these files to reflect the actual values

                        Changes in persistence.xml
                        Change <property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect"/>
                        to <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>

                        Changes in
                        1. Change database.url=jdbc\:as400\://dummy/dummy
                        to database.url=jdbc:db2://yourhost:yourport/databasename
                        2. Change 0JDBCDriver

                        After making this change, it was smooth sailing. Steps below just worked fine.

                        database introspect --schema foo
                        database reverse engineer --schema foo

                        Hope this helps.


                        • #13
                          The DB2_EXPRESS_C option will give you the closest configuration for most DB2 platforms apart from AS/400. The DB2_400 option is unique in that it uses a completely different driver (jt400), which is not supplied by IBM.


                          • #14
                            I've also tried the same thing, and some variations of it. And I always stop on the step 4. mvn bundle:bundle with the following resulting message:

                            [INFO] Scanning for projects...
                            [INFO] ------------------------------------------------------------------------
                            [INFO] Building com-ibm-db2-roo-jdbc
                            [INFO] ------------------------------------------------------------------------
                            [INFO] --- maven-bundle-plugin:2.3.4:bundle (default-cli) @ ---
                            [WARNING] Warning building bundle undle: : Split package MET
                            Use directive -split-package:=(merge-first|merge-last|error|first) on Export/Private Package instruction to get rid of t
                            his warning
                            Package found in [Jar:., Jar:db2jcc]
                            Reference from C:\WINDOWS\Profiles\mapereira\.m2\repository\com\i bm\db2jcc\9.7.2\db2jcc-9.7.2.jar
                            Classpath [Jar:., Jar:db2jcc]
                            [WARNING] Warning building bundle undle: : Did not find matc
                            hing referal for*
                            [WARNING] Warning building bundle undle: : Did not find matc
                            hing referal for org.w3c.*
                            [WARNING] Warning building bundle undle: : Did not find matc
                            hing referal for org.xml.*
                            [ERROR] Error building bundle undle: : Unresolved references
                            to [,] by class(es) on the Bundle-Classpath[Jar:dot]: [com/ibm/db2/jcc/b/md.class, C
                            [ERROR] Error(s) found in bundle configuration
                            [INFO] ------------------------------------------------------------------------
                            [INFO] BUILD FAILURE
                            [INFO] ------------------------------------------------------------------------
                            [INFO] Total time: 6.125s
                            [INFO] Finished at: Mon Jan 14 13:09:05 EST 2013
                            [INFO] Final Memory: 4M/15M
                            [INFO] ------------------------------------------------------------------------
                            [ERROR] Failed to execute goal org.apache.felix:maven-bundle-plugin:2.3.4:bundle (default-cli) on project
                            o.jdbc.db2jcc: Error(s) found in bundle configuration -> [Help 1]

                            I'm still trying to search for a solution on other means, withouy success so far. Nevertheless, I thank you in advance for any help.


                            • #15
                              After following Wallenborn's instructions, I'm getting an Unresolved Constraint error:

                              [ [98]] FrameworkEvent ERROR
                              org.apache.felix.log.LogException: org.osgi.framework.BundleException: Unresolved constraint in bundle
                              DBC [98]: Unable to resolve 98.0: missing requirement [98.0] package; (
                              Any idea how to fix this?