6 Replies Latest reply on Jan 12, 2002 9:39 AM by davidjencks

    unable to connect to db from entity bean

    sachin

      Dear All,
      I have a problem in accessing database from the entity bean. I am using BMP. I am using jboss 2.4.x.


      The resource reference part of ejb-jar.xml is as:

      <resource-ref>
      <res-ref-name>java:/MacaDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>

      Also the related content of jboss.jcml is:


      org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl
      MacaDB
      jdbc:postgresql://IP:Port/sid
      user
      pass
      false



      My standardjaws.xml content is:
      java:/MacaDB
      <type-mapping>MacaDB</type-mapping>
      false


      On trying to access db, i am getting an exception as:

      TRANSACTION ROLLBACK EXCEPTION:Unable to connect to database. jdbc not bound; nested exception is:
      javax.ejb.EJBException: Unable to connect to database. jdbc not bound
      [UsersEB] javax.ejb.EJBException: Unable to connect to database. jdbc not bound
      [UsersEB] at macamanageuser.UsersEB.setEntityContext(UsersEB.java:520)
      [UsersEB] at org.jboss.ejb.EntityEnterpriseContext.(EntityEnterpriseContext.java:78)
      [UsersEB] at org.jboss.ejb.plugins.EntityInstancePool.create(EntityInstancePool.java:81)
      [UsersEB] at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.java:143)
      [UsersEB] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:143)
      [UsersEB] at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:108)
      [UsersEB] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:135)
      [UsersEB] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:307)
      [UsersEB] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:86)
      [UsersEB] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:103)
      [UsersEB] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:106)
      [UsersEB] at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:420)
      [UsersEB] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRMPContainerInvoker.java:441)
      [UsersEB] at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invokeHome(HomeProxy.java:237)
      [UsersEB] at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:182)
      [UsersEB] at $Proxy71.findByUser_UserName(Unknown Source)
      [UsersEB] at macamanageuser.UsersSB.getUserId(UsersSB.java:435)
      [UsersEB] at java.lang.reflect.Method.invoke(Native Method)
      [UsersEB] at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:543)
      [UsersEB] at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:87)
      [UsersEB] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
      [UsersEB] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:307)
      [UsersEB] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:99)
      [UsersEB] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:128)
      [UsersEB] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
      [UsersEB] at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:286)
      [UsersEB] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:489)
      [UsersEB] at org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(GenericProxy.java:335)
      [UsersEB] at org.jboss.ejb.plugins.jrmp.interfaces.StatelessSessionProxy.invoke(StatelessSessionProxy.java:123)
      [UsersEB] at $Proxy49.getUserId(Unknown Source)



      The message is that 'jdbc not bound'. The ip,port,user and password needed to connect are correct.
      Also i have included the driver string into the jboss.jcml.

      There is something wrong on my part, but am unable to spot it.
      Can anyone help me?

      Thanks in advance for the help

      Sachin

        • 1. Re: unable to connect to db from entity bean
          jvramana

          hi,
          Make sure your ConnectionFactory has implemented
          javax.naming.Referenceable interface.
          don't let getReference() method return null..

          Hope you may success now,if I understood your problem correctly...


          Ramana

          • 2. Re: unable to connect to db from entity bean
            davidjencks

            It's a little hard to tell since you don't favor us with your code in which the exception is thrown, however have you checked jndiView to make sure the datasource is bound under the name you are looking it up under?

            Also if you are using CMT be sure that you get connections after the transaction has started and release (close) them before it ends.

            I believe the other response is not relevant since you are not using the jca framework.

            • 3. Re: unable to connect to db from entity bean
              sachin

              Hi,
              Thanks for the help. i have now solved the problem and my application works fine. I actually had developed the application on J2EE server by SUN. Using that i was relieved from the work of forming the xml files. Also the convention of the jndi naming is different from that of jboss. so when i started porting the application from j2ee to jboss, i did not make the necessary changes in the jndi name.
              Like j2ee needs jndi names in java:comp/env/...

              Also i used jsp in my application and had to solve the classpath problem. i got all the needed help from the forums here.
              So thanks to all who contributed and i will also try to contribute something now based on my past experience.
              Also i have another requirement of accessing a lotus notes database from my application along with the relational db. Has anybody come across such a requirement or content on web or discussion thread?

              Thanks in advance,
              Sachin

              • 4. Re: unable to connect to db from entity bean
                davidjencks

                Ideally, ibm/lotus will release a jca connector for lotus notes. However a quick look at their website does not lead me to think they are planning a standards based solution. What java connectivity to lotus is there?

                • 5. Re: unable to connect to db from entity bean
                  sachin

                  As i mentioned that my software was supposed to work with a relational database. I had used bmp and thus have all the sql queries in my code.
                  Now i want to access an already existing lotus notes db say for example want to get data from lotus notes db which is equivalent to firing a select query in relational db.
                  I would not want to change my coding to provide for lotus notes db coz my product is ready. Ofcourse i can have a new version for that but i want to explore if i can somehow form a interface with notes db.
                  I have just tried looking at connecter architecture.
                  Will post details if i come to know of something.

                  Sachin

                  • 6. Re: unable to connect to db from entity bean
                    davidjencks

                    If they have a jdbc driver (which another post indicates they do) and it will do enough of what you want by all means use it.