13 Replies Latest reply on Jul 27, 2007 10:54 AM by Warg Krumpf

    How to connect my EJB to Firebird database?

    Grigoriy Zaspa Newbie

      Hello,

      Can anybody explain me how I can connect an EJB from my application to Firebird database? I copied firebird-ds.xml and jaybird.rar to deploy folder. What should I do to use this new datasource in my EJB?

        • 1. Re: How to connect my EJB to Firebird database?
          Vicky Kak Master

          Can you try replacing the <rar-name>firebirdsql.rar</rar-name> by
          <rar-name>jaybird.rar</rar-name> in firebird-ds.xml?

          • 2. Re: How to connect my EJB to Firebird database?
            Grigoriy Zaspa Newbie

            Sure, I corrected my firebird-ds.xml, replacing firebird.rar with jaybird-2.1.1.rar. But as soon as I declare Entity Manager in my EJB, that EJB fails.

            • 3. Re: How to connect my EJB to Firebird database?
              Grigoriy Zaspa Newbie

              Sure, I corrected my firebird-ds.xml, replacing firebird.rar with jaybird-2.1.1.rar. But as soon as I declare Entity Manager in my EJB, that EJB fails.

              • 4. Re: How to connect my EJB to Firebird database?
                Vicky Kak Master

                What is the error you are getting , give the details about the same?

                • 5. Re: How to connect my EJB to Firebird database?
                  Grigoriy Zaspa Newbie

                  OK, I try to run the simplest EJB working with Firebird DB. I'll try to describe you as short and as full as I can. If any other information is necessary, please, ask.

                  I put firebird-ds.xml in deploy folder and corrected it. I seem it was deployed OK - in JMX console in jboss.jca part I see:

                  name='jaybird-2.1.1.rar',service=RARDeployment
                  name='jboss-ha-local-jdbc.rar',service=RARDeployment
                  ...
                  name=DefaultDS,service=DataSourceBinding
                  name=DefaultDS,service=LocalTxCM
                  name=DefaultDS,service=ManagedConnectionFactory
                  name=DefaultDS,service=ManagedConnectionPool
                  name=FIrebirdDS,service=ConnectionFactoryBinding
                  name=FIrebirdDS,service=ManagedConnectionFactory
                  name=FIrebirdDS,service=ManagedConnectionPool
                  name=FIrebirdDS,service=TxCM
                  ...

                  Then, I have a Java EE project with one EJB. I include persistence.xml in META-INF of the project, in which I write:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <persistence-unit name="order" transaction-type="JTA">
                  <jta-data-source>java:/FIrebirdDS</jta-data-source>
                  </persistence-unit>

                  My EJB begins with:
                  @Stateless
                  @RemoteBinding(jndiBinding="ejb/Person")
                  public class PersonBean implements Person {

                  //@PersistenceContext EntityManager em;

                  When I deploy my .ear with this EJB, I get an error message in JBoss console with the last part:
                  --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
                  ObjectName: jboss.jca:name=FIrebirdDS,service=DataSourceBinding
                  State: NOTYETINSTALLED
                  Depends On Me:
                  persistence.units:ear=EJB3Test.ear,jar=EJB3Test.jar,unitName=order
                  persistence.units:ear=EJB3Test.ear,jar=EJB3Test.jar,unitName=order
                  persistence.units:ear=EJB3Test.ear,jar=EJB3Test.jar,unitName=order

                  But nevertheless .ear is deployed and I can reach my PersonBean EJB from a remote client on JNDI name and call it's business method. But as soon as I uncomment
                  //@PersistenceContext EntityManager em;
                  and redeploy my .ear, I cannot reach PersonBean EJB any more -
                  Object ref = context.lookup("ejb/Person"); in my client generates NameNotFoundException.

                  • 6. Re: How to connect my EJB to Firebird database?
                    Vicky Kak Master

                    Let us first see if we are able to deploy the DS for Firebird .
                    Can you please post your -ds.xml file ?
                    Also from where have you downloaded the rar file , give me the location ?
                    Also can you try calling the simple code from the jsp to check of the DataSource is working , here is the code

                    InitialContext context = new InitailContext();
                    DataSource ds = (DataSource)context.lookup("java:/FIrebirdDS");
                    Connection con = ds.getConnection();
                    


                    Can you see if this work first ?



                    • 7. Re: How to connect my EJB to Firebird database?
                      Grigoriy Zaspa Newbie

                      I inserted the code

                      InitialContext context = new InitailContext();
                      DataSource ds = (DataSource)context.lookup("java:/FIrebirdDS");
                      Connection con = ds.getConnection();

                      in a servlet. Running that I got an exception with the trace:
                      ----------------------------------------------------------------------
                      18:13:10,343 INFO [CachedConnectionManager] Closing a connection for you. Plea
                      se close them yourself: org.firebirdsql.jdbc.FBConnection@a4effe
                      java.lang.Throwable: STACKTRACE
                      at org.jboss.resource.connectionmanager.CachedConnectionManager.register
                      Connection(CachedConnectionManager.java:290)
                      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateC
                      onnection(BaseConnectionManager2.java:417)
                      at org.jboss.resource.connectionmanager.BaseConnectionManager2$Connectio
                      nManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
                      at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:95)

                      at web.ComputeServlet.init(ComputeServlet.java:50)
                      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
                      java:1105)
                      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.jav
                      a:757)
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
                      alve.java:130)
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
                      alve.java:178)
                      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
                      yAssociationValve.java:175)
                      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
                      e.java:74)
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
                      ava:126)
                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
                      ava:105)
                      at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConne
                      ctionValve.java:156)
                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
                      ve.java:107)
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
                      a:148)
                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
                      :869)
                      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
                      rocessConnection(Http11BaseProtocol.java:664)
                      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
                      int.java:527)
                      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
                      kerThread.java:112)
                      at java.lang.Thread.run(Thread.java:595)
                      --------------------------------------------------------------------
                      In this trace the row
                      web.ComputeServlet.init(ComputeServlet.java:50)
                      points on my code row
                      Connection con = ds.getConnection();

                      • 8. Re: How to connect my EJB to Firebird database?
                        Weston M. Price Master

                        The stacktrace is simply informing you that you didn't close the connection. What this means is that your FirebirdDS can be acquired from JNDI and you can open a connection.

                        From what you have posted up to this point there should be nothing preventing you from using the DS in your EJB3 code. The deployment

                        <?xml version="1.0" encoding="UTF-8"?>
                        <persistence-unit name="order" transaction-type="JTA">
                        <jta-data-source>java:/FIrebirdDS</jta-data-source>
                        </persistence-unit>
                        


                        May have a typo. Is 'FIrebirdDS' what you intend, or should it be 'FirebirdDS'?

                        Please post the full contents of your *-ds.xml file.




                        • 9. Re: How to connect my EJB to Firebird database?
                          Grigoriy Zaspa Newbie

                          Weston,

                          I just copied firebird-ds.xml from JBoss4.0.5 doc folder and changed rar and database names. The jndi name FIrebirdDS I didn't change. Here's the full text of my firebird-ds.xml:

                          <?xml version="1.0" encoding="UTF-8"?>
                          
                           <!-- $Id: firebird-ds.xml 41641 2006-03-02 17:41:11Z dimitris $ -->
                          
                           <!-- ==================================================================== -->
                           <!-- New ConnectionManager setup for firebird dbs using jca-jdbc xa driver-->
                           <!-- Build jmx-api (build/build.sh all) and view for config documentation -->
                           <!-- ==================================================================== -->
                          
                          <connection-factories>
                          
                           <!--FBManager can be used to create and drop databases.
                           Drop is especially useful during testing, since it
                           assures a clean start next time. -->
                           <mbean code="org.firebirdsql.management.FBManager" name="jboss.jca:service=FirebirdManager">
                           <attribute name="FileName">${jboss.server.data.dir}${/}fbtest.gdb</attribute>
                           <attribute name="UserName">sysdba</attribute>
                           <attribute name="Password">masterkey</attribute>
                           <attribute name="CreateOnStart">true</attribute>
                           <attribute name="DropOnStop">false</attribute>
                           </mbean>
                          
                           <tx-connection-factory>
                           <jndi-name>FIrebirdDS</jndi-name>
                           <xa-transaction/>
                           <track-connection-by-tx/>
                           <rar-name>jaybird-2.1.1.rar</rar-name>
                           <connection-definition>javax.sql.DataSource</connection-definition>
                           <config-property name="Database" type="java.lang.String">localhost/3050:c:/1/fbtest.gdb</config-property>
                           <user-name>sysdba</user-name>
                           <password>masterkey</password>
                           <!--additional properties. only use one way of setting tx isolation, please
                           <config-property name="TransactionIsolation"></config-property>
                           <config-property name="TransactionIsolationName">TRANSACTION_READ_COMMITTED</config-property>
                           <config-property name="BlobBufferLength"></config-property>
                           <config-property name="Encoding">UNICODE_FSS</config-property>
                           -->
                           <min-pool-size>0</min-pool-size>
                           <!-- sql to call when connection is created
                           <new-connection-sql>some arbitrary sql</new-connection-sql>
                           -->
                           <!-- sql to call on an existing pooled connection when it is obtained from pool
                           <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
                           -->
                           <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
                           <metadata>
                           <type-mapping>Firebird</type-mapping>
                           </metadata>
                           </tx-connection-factory>
                          
                          </connection-factories>
                          

                          Can you explain me why I get the following message in JBoss console when deploying my .ear (I wrote of that before - actually it is the last part of the message) and if this problem may cause problems for the work of the EJB:

                          --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
                          ObjectName: jboss.jca:name=FIrebirdDS,service=DataSourceBinding
                          State: NOTYETINSTALLED
                          Depends On Me:
                          persistence.units:ear=EJB3Test.ear,jar=EJB3Test.jar,unitName=order
                          persistence.units:ear=EJB3Test.ear,jar=EJB3Test.jar,unitName=order
                          persistence.units:ear=EJB3Test.ear,jar=EJB3Test.jar,unitName=order

                          • 10. Re: How to connect my EJB to Firebird database?
                            Vicky Kak Master

                            Can you post the server.log file of the JBOSS?

                            • 11. Re: How to connect my EJB to Firebird database?
                              Grigoriy Zaspa Newbie

                              Now the code in servlet works. I wrote in servlet init method

                              InitialContext context = new InitialContext();
                              DataSource ds = (DataSource)context.lookup("java:/FIrebirdDS");
                              Connection con = ds.getConnection();
                              Statement st=con.createStatement();
                              ResultSet rs=st.executeQuery("select * from person");
                              

                              Everything works fine, there are proper data in ResultSet after executing st.executeQuery method. So, FIrebirdDS works. But the old problem stays. In the same servlet init method I try to use my EJB:

                              Object ref = context.lookup("ejb/Person");
                              home = (Person) ref;
                              

                              Again, it works, I can then execute the business method of my PersonBean. But when inside PersonBean EJB I uncomment the line
                              //@PersistenceContext EntityManager em;

                              I get an exception
                              8:50:56,093 ERROR [STDERR] javax.naming.NameNotFoundException: ejb not bound
                              18:50:56,093 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
                              18:50:56,093 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
                              18:50:56,093 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
                              18:50:56,093 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
                              18:50:56,093 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
                              18:50:56,093 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
                              18:50:56,093 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:351)
                              18:50:56,093 ERROR [STDERR] at web.ComputeServlet.init(ComputeServlet.java:56)
                              18:50:56,093 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
                              ...
                              where
                              web.ComputeServlet.init(ComputeServlet.java:56)
                              is line
                              Object ref = context.lookup("ejb/Person");
                              of my servlet.


                              • 12. Re: How to connect my EJB to Firebird database?
                                Grigoriy Zaspa Newbie

                                When I change FIrebirdDS to DefaultDS in persistence.xml, it works. But as soon as I change back to FIrebirdDS, I get again
                                NameNotFoundException: ejb not bound

                                • 13. Re: How to connect my EJB to Firebird database?
                                  Warg Krumpf Newbie

                                  The wiki says athttp://wiki.jboss.org/wiki/Wiki.jsp?page=SetUpAFirebirdDatasource
                                  to use

                                  <local-tx-datasource>
                                  instead of
                                  <tx-connection-factory>

                                  and i can confirm that it works this way.

                                  I just wonder, is this a bug or a feature? tx-connection-factory seems like more advanced, but it ceased to work with the current Jboss 4.2.1 / Jaybird 2.1.1 -combination...

                                  Are there any drawbacks in using the local-tx-datasource? Or should we just forget about this issue?

                                  Regards,

                                  Marco