4 Replies Latest reply on May 6, 2002 8:14 AM by Pete Luellen

    BMP - cannot access datasource

    Pete Luellen Newbie

      OK, I know BMP is a distant second choice for persistence mechanisms. I'm creating a BMP enitity bean as part of a tutorial and seem to be having trouble getting to my MySqlDS datasource from within the bean (in order to persist the data). Here's my bean's getConnection() method:

      private Connection getConnection() throws Exception {
      try {
      Context ctx = new InitialContext();
      DataSource ds = (DataSource) ctx.lookup("java:/MySqlDS");
      return ds.getConnection();
      } catch (Exception e) {
      System.err.println("unable to get datasource: " + e.getMessage());
      e.printStackTrace();
      throw e;
      }
      }

      Here's the server output when I exercise a client against the bean:

      10:34:59,914 ERROR [STDERR] java.lang.SecurityException: Invalid authentication attempt, principal=null


      Here's part of my ejb-jar.xml file:
      <ejb-jar>
      ...
      <enterprise-beans>

      <ejb-name>Account</ejb-name>
      ch6.AccountHome
      ch6.Account
      <local-home>ch6.AccountLocalHome</local-home>
      ch6.AccountLocal
      <ejb-class>ch6.AccountBean</ejb-class>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>ch6.AccountPK</prim-key-class>
      False

      <resource-ref>
      <res-ref-name>MySqlDS</res-ref-name>
      MySQL test database
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>


      </enterprise-beans>
      ...
      </ejb-jar>


      Here's my jboss.xml file:

      false
      <container-configurations />
      <resource-managers />
      <enterprise-beans>

      <ejb-name>Account</ejb-name>
      <jndi-name>ch6/Account</jndi-name>
      <configuration-name></configuration-name>

      <resource-ref>
      <res-ref-name>MySqlDS</res-ref-name>
      <jndi-name>java:/MySqlDS</jndi-name>
      </resource-ref>


      </enterprise-beans>


      I believe my MySqlDS is configured properly: It has a corresponding MySqlDbRealm in the login-conf.xml file and works just fine with some CMP beans I've deployed and used. I'm running jboss-3.0.0RC1.

      What am I doing wrong? It looks to me like my bean is finding the datasource but is getting rejected for security reasons.

      Thanks for the help.