4 Replies Latest reply on Aug 1, 2002 9:35 AM by davidjencks

    connecting to Firebird database

    rramirez

      I'm trying to connect to a firebird database and I'm getting the following exception:

      13:37:48,676 INFO [FBManagedConnectionFactory] Could not get a db connection!
      org.firebirdsql.gds.GDSException:
      at org.firebirdsql.jgds.GDS_Impl.connect(GDS_Impl.java:1240)
      at org.firebirdsql.jgds.GDS_Impl.isc_attach_database(GDS_Impl.java:263)
      at org.firebirdsql.jgds.GDS_Impl.isc_attach_database(GDS_Impl.java:247)
      at org.firebirdsql.jca.FBManagedConnectionFactory.createDbHandle(FBManagedConnectionFactory.java:515)
      at org.firebirdsql.jca.FBManagedConnectionFactory.assureDbHandle(FBManagedConnectionFactory.java:524)
      at org.firebirdsql.jca.FBManagedConnection.(FBManagedConnection.java:111)

      ....
      at org.jboss.Main.boot(Main.java:142)
      at org.jboss.Main$1.run(Main.java:375)
      at java.lang.Thread.run(Thread.java:479)
      13:37:48,786 INFO [EjbModule] Remove JSR-77 EJB Module: jboss.management.single:J2EEApplication= ,J2EEServer=Single,j2eeType=EJBModule,name=andrea.jar
      13:37:48,796 ERROR [EjbModule] Initialization failed
      org.jboss.deployment.DeploymentException: Error while fixing table name; - nested throwable: (java.sql.SQLException: Problem getting connection: javax.resource.ResourceException: could not get a db co
      nnection!)
      at org.jboss.ejb.plugins.cmp.jdbc.SQLUtil.fixTableName(SQLUtil.java:67)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.(JDBCEntityBridge.java:103)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.create(JDBCStoreManager.java:332)
      at org.jboss.ejb.plugins.CMPPersistenceManager.create(CMPPersistenceManager.java:155)

      ....


      I'm using jboss-3.0.0.

      The following is what I have done to try to get this working.
      I placed the firebirdsql.rar file in the /jboss/server/default/deploy directory.
      I edited the firebird-service.xml file and placed it in the deploy directory.

      I can connect to the Firebird database using the firebirdsql.jar file without using jboss.

      Here are the configuration files:

      -------------------------- ejb-jar.xml -------------------
      <?xml version="1.0"?>



      <ejb-jar>

      <enterprise-beans>

      The Account Bean that handles the account information
      <ejb-name>AccountEJB</ejb-name>
      com.andrea.server.impl.AccountHomeRemote
      com.andrea.server.impl.AccountRemote
      <ejb-class>com.andrea.server.impl.AccountBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>AccountSchema</abstract-schema-name>
      <cmp-field><field-name>accountId</field-name></cmp-field>
      <cmp-field><field-name>email</field-name></cmp-field>
      <cmp-field><field-name>passcode</field-name></cmp-field>
      <cmp-field><field-name>phrase</field-name></cmp-field>
      <cmp-field><field-name>phraseResponse</field-name></cmp-field>
      <cmp-field><field-name>name</field-name></cmp-field>
      <primkey-field>accountId</primkey-field>

      </enterprise-beans>


      <assembly-descriptor>
      <security-role>

      This role represents everyone who is allowed full access
      to the Account EJB.

      <role-name>everyone</role-name>
      </security-role>

      <method-permission>
      <role-name>everyone</role-name>

      <ejb-name>AccountEJB</ejb-name>
      <method-name>*</method-name>

      </method-permission>

      <container-transaction>

      <ejb-name>AccountEJB</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>

      </ejb-jar>

      -------------------------- ejb-jar.xml --------------------------

      -------------------------- jboss.xml --------------------------
      <?xml version="1.0" encoding="Cp1252"?>


      <enterprise-beans>

      <ejb-name>AccountEJB</ejb-name>
      <jndi-name>AccountHomeRemote</jndi-name>

      </enterprise-beans>


      -------------------------- jboss.xml --------------------

      ----------- jbosscmp-jdbc.xml -----------
      <?xml version="1.0" encoding="UTF-8"?>


      <!-- ===================================================================== -->
      <!-- -->
      <!-- Standard JBossCMP-JDBC Configuration -->
      <!-- -->
      <!-- ===================================================================== -->


      <jbosscmp-jdbc>


      java:/AndreaDS
      <datasource-mapping>InterBase</datasource-mapping>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <read-only>false</read-only>
      <pk-constraint>true</pk-constraint>
      <preferred-relation-mapping>foreign-key</preferred-relation-mapping>


      <enterprise-beans>

      <ejb-name>AccountEJB</ejb-name>
      <table-name>account</table-name>

      <cmp-field>
      <field-name>accountId</field-name>
      <column-name>accountId</column-name>
      <jdbc-type>BIGINT</jdbc-type>
      <sql-type>NUMERIC(12,0)</sql-type>
      </cmp-field>

      <cmp-field>
      <field-name>email</field-name>
      <column-name>email</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(80)</sql-type>
      </cmp-field>

      <cmp-field>
      <field-name>passcode</field-name>
      <column-name>passcode</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(40)</sql-type>
      </cmp-field>

      <cmp-field>
      <field-name>phrase</field-name>
      <column-name>phrase</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(200)</sql-type>
      </cmp-field>

      <cmp-field>
      <field-name>phraseResponse</field-name>
      <column-name>phraseResponse</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(100)</sql-type>
      </cmp-field>

      <cmp-field>
      <field-name>name</field-name>
      <column-name>name</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(80)</sql-type>
      </cmp-field>


      </enterprise-beans>
      </jbosscmp-jdbc>

      -------------------------- jbosscmp-jdbc.xml -------------

      -------------------------- firebird-service.xml ------------
      <?xml version="1.0" encoding="UTF-8"?>

      <!-- ==================================================================== -->
      <!-- New ConnectionManager setup for firebird dbs using jca-jdbc xa driver-->
      <!-- Build jmx-api (build/build.sh all) and view for config documentation -->
      <!-- ==================================================================== -->



      <!--FBManager can be used to create and drop databases.
      Drop is especially useful during testing, since it
      assures a clean start next time. -->

      H:/jboss-3.0.0/server/default/db/andrea.gdb
      sysdba
      masterkey
      false
      false



      <!--make the rar deploy - A BIG HACK till xslt based deployment is written-->
      jboss.jca:service=RARDeployer

      <depends optional-attribute-name="ManagedConnectionFactoryName">

      <!--more hack-->
      <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=Firebird Database Connector


      <!--config-property>
      <config-property-name>Server</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
      <config-property-value>localhost</config-property-value>
      </config-property>
      <config-property>
      <config-property-name>Port</config-property-name>
      <config-property-type>java.lang.Integer</config-property-type>
      <config-property-value>3050</config-property-value>
      </config-property-->
      <config-property>
      <config-property-name>Database</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
      <config-property-value>H:/jboss-3.0.0/server/default/db/andrea.gdb</config-property-value>
      </config-property>
      <config-property>
      <config-property-name>UserName</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
      <config-property-value>sysdba</config-property-value>
      </config-property>
      <config-property>
      <config-property-name>Password</config-property-name>
      <config-property-type>java.lang.String</config-property-type>
      <config-property-value>masterkey</config-property-value>
      </config-property>


      AndreaDS



      <depends optional-attribute-name="ManagedConnectionPool">


      5
      50
      5000
      15
      <!--criteria indicates if Subject (from security domain) or app supplied
      parameters (such as from getConnection(user, pw)) are used to distinguish
      connections in the pool. Choices are
      ByContainerAndApplication (use both),
      ByContainer (use Subject),
      ByApplication (use app supplied params only),
      ByNothing (all connections are equivalent, usually if adapter supports
      reauthentication)-->
      ByContainer


      <depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager
      <!-- Include a login module configuration named FirebirdDBRealm.
      Update your login-conf.xml, here is an example for a
      ConfiguredIdentityLoginModule:

      <application-policy name = "FirebirdDBRealm">

      <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
      <module-option name = "principal">sysdba</module-option>
      <module-option name = "userName">sysdba</module-option>
      <module-option name = "password">masterkey</module-option>
      <module-option name = "managedConnectionFactoryName">jboss.jca:service=XaTxCM,name=AndreaDS</module-option>
      </login-module>

      </application-policy>

      NOTE: the application-policy name attribute must match SecurityDomainJndiName, and the
      module-option name = "managedConnectionFactoryName"
      must match the object name of the ConnectionManager you are configuring here.
      -->
      <!--comment out this line if you want component managed security or want
      to use the default values in the ManagedConnectionFactoryProperties -->
      <!--
      FirebirdDBRealm
      -->
      <depends optional-attribute-name="JaasSecurityManagerService">jboss.security:name=JaasSecurityManager

      java:/TransactionManager




      ------------- firebird-service.xml -------------


      Any help would be greatly appreaciated.
      I'm using jboss 3.0, JDK 1.3.1_03-b03 and Firebird 1.0

      Thanks,
      Ruben

        • 1. Re: connecting to Firebird database
          davidjencks

          THe server and port config-properties don't really exist. You need to include them in the database property like this:

          <config-property>
          <config-property-name>Database</config-property-name>
          <config-property-type>java.lang.String</config-property-type>
          <config-property-value>localhost/3050:H:/jboss-3.0.0/server/default/db/andrea.gdb</config-property-value>
          </config-property>


          • 2. Re: connecting to Firebird database
            rramirez

            That solved the problem. I can access my beans and create objects and they show up in the database. The only problem is that I'm getting a different error. I think the error is happening when JBoss is trying to destroy the connection. Here's the output from jboss:

            09:04:55,493 ERROR [STDERR] java.lang.NullPointerException
            09:04:55,503 ERROR [STDERR] at org.firebirdsql.jca.FBManagedConnectionFactory.removeDbHandleIfLastUse(FBManagedConnectionFactory.java:468)
            09:04:55,503 ERROR [STDERR] at org.firebirdsql.jca.FBManagedConnectionFactory.releaseDbHandle(FBManagedConnectionFactory.java:560)
            09:04:55,513 ERROR [STDERR] at org.firebirdsql.jca.FBManagedConnection.destroy(FBManagedConnection.java:339)
            09:04:55,523 ERROR [STDERR] at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.doDestroy(InternalManagedConnectionPool.java:250)
            09:04:55,523 ERROR [STDERR] at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.removeTimedOut(InternalManagedConnectionPool.java:168)
            09:04:55,533 ERROR [STDERR] at org.jboss.resource.connectionmanager.IdleRemover$1.run(IdleRemover.java:70)
            09:04:55,533 ERROR [STDERR] at java.lang.Thread.run(Thread.java:479)

            I changed the IdleTimeoutMinues from 15 to 5 and I'm getting the error after I access my beans and don't access jboss for a period of 5 minutes. After I get the error I can still access my beans but looks like I don't get the error again. I'm accessing an entity bean which in turn accesses a stateless session bean. Don't know if that might cause this problem.

            Thanks,
            Ruben

            • 3. Re: connecting to Firebird database
              bambaloo

              hi there,

              i get the exact same problem. I changed the FBManagedConnectionFactory.java (part of the jca-jdbc adapter) to not throw the null pointer.

              The method to look for is:

              private boolean removeDbHandleIfLastUse(isc_db_handle db)
              {
              synchronized(dbHandleUsage)
              {
              Integer i = (Integer)dbHandleUsage.get(db);
              if (i.intValue() == 1) <= null pointer is thrown here because 'i' will be null
              {
              dbHandleUsage.remove(db);
              return true;
              } // end of if ()
              return false;
              }
              }

              I check that 'i' is null, if it is i return false.

              I am sure this is not the best way to fix it, i am trying to find out why JBoss is calling this method with a db handle that has already been removed. Not sure if it is the way i have set up the datasource, or a jboss problem. Probably me.

              One thing i do know is that i didn't get this problem with JBoss3.0.0alpha, it has only occurred in final JBoss3.0.0

              • 4. 3857608
                davidjencks

                Could you file this as a bug on the firebird site?

                Thanks
                david jencks