1 Reply Latest reply on Oct 14, 2004 1:08 PM by Tom Clifford

    JBoss says bean is not a jbosscmp-jdbc-managed cmp entity

    Tom Clifford Newbie


      As part of my own self-education in EJB, I am trying to get
      some of Brett McLaughlin's code from
      Java Enterprise Applications, Vol I (O'Reilly, 2002)
      to work in JBoss.

      I have implemented only the Office part of his mySql database,
      that part of his bean code, and have tried to implement his
      stateless session bean 'SequenceBean' to look up the next key
      available to add offices.

      I have set up the jbosscmp-jdbc.xml and ejb-jar.xml, I believe,
      according to examples I have seen, but I still get the following error
      when I deploy the jar file:


      22:38:56,971 INFO [EjbModule] Deploying Office
      22:38:56,981 INFO [EjbModule] Deploying SequenceBean
      22:38:57,351 ERROR [EntityContainer] Starting failed jboss.j2ee:jndiName=Office,
      org.jboss.deployment.DeploymentException: Configuration found in jbosscmp-jdbc.x
      ml for entity SequenceBean but bean is not a jbosscmp-jdbc-managed cmp entity in
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCApplicationMetaData.(JDBCApplicationMetaData.java:358)
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCXmlFileLoader.load(JDBCXm
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadJDBCEntityMetaDat
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.initStoreManager(JDBC
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManage
      at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManag
      at org.jboss.ejb.EntityContainer.startService(EntityContainer.java:340)
      at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanS
      ......et. cetera......


      when I try to leave out the jbosscmp-ejb.xml file completely,
      the jar file deploys without errors, but when I run the client,
      it gives me an error that jdbc is not bound:

      >java com.sample.client.EntityCreator

      Clifford IT Services EntityCreator program.

      setting security policy...
      got InitialContext...
      ...is: [javax.naming.InitialContext@291aff]
      Looking up the Office bean.
      got context...
      refobj = OfficeHome
      create DallasOffice...
      Error in EntityCreator: OfficeBean: Error getting primary key value: Sequence Be
      an Exception: Error getting JDBC resources: jdbc not bound: jdbc not bound


      I can email a zip file with the pertinent files included,
      if anyone might be interested in this issue. Maybe it's just
      my limited educational resources, but this has me puzzled.

      I've checked the JBoss forums and do not see anything
      that helps much. A google search does not come up
      with much, either.

      Thanks for anything that you might point out.

      I'm running JBoss v4.0.0RC2, and have tried the same with
      RC1, and with JBoss v2.4.2.
      I'm running Apache 2.0.48 and Tomcat V5 on the same machine.

      Tom C.

        • 1. Re: JBoss says bean is not a jbosscmp-jdbc-managed cmp entit
          Tom Clifford Newbie

          As a follow-up, I thought I should post at least some part of the
          files I'm working with.

          The OfficeBean:

          package com.sample.ejb.office;

          import javax.ejb.CreateException;
          import javax.naming.Context;
          import javax.naming.InitialContext;
          import javax.naming.NamingException;
          import javax.rmi.*;
          import java.rmi.*;

          import com.sample.ejb.sequence.SequenceException;
          import com.sample.ejb.sequence.SequenceLocal;
          import com.sample.ejb.sequence.SequenceLocalHome;
          //import com.sample.ejb.sequence.SequenceHome;
          import com.sample.ejb.util.EntityAdapter;

          public abstract class OfficeBean extends EntityAdapter {

          public Integer ejbCreate(String city, String state)
          throws CreateException {

          // Get the next primary key value
          try {

          System.out.println( "OfficeBean: get InitialContext..." );
          Context ctx = new InitialContext( );
          System.out.println( "OfficeBean: got InitialContext..." );
          System.out.println( "OfficeBean: ...is: [" + ctx + "]" );

          // Note that RMI-IIOP narrowing is not required
          System.out.println("OfficeBean: looking up the SequenceLocalHome...");
          SequenceLocalHome home = (SequenceLocalHome)
          System.out.println("OfficeBean: SequenceLocal.create()...");
          SequenceLocal sequence = home.create();
          System.out.println("OfficeBean: looking up OfficeKey...");
          String officeKey =
          Integer id = sequence.getNextValue(officeKey);

          // Set values

          return null;
          } catch (NamingException e) {
          throw new CreateException("OfficeBean: Could not obtain an " +
          "InitialContext.\n msg: [" + e.getMessage() + "]\n");
          } catch (SequenceException e) {
          throw new CreateException("OfficeBean: Error getting primary key value: " +

          public void ejbPostCreate(String city, String state) {
          // Empty implementation

          public OfficeInfo getInfo() {
          return new OfficeInfo(getId().intValue(), getCity(), getState());

          public void setInfo(OfficeInfo officeInfo) {
          setId(new Integer(officeInfo.getId()));

          public abstract Integer getId();
          public abstract void setId(Integer id);

          public abstract String getCity();
          public abstract void setCity(String city);

          public abstract String getState();
          public abstract void setState(String state);

          The SequenceBean:

          package com.sample.ejb.sequence;

          import java.sql.Connection;
          import java.sql.DriverManager;
          import java.sql.ResultSet;
          import java.sql.SQLException;
          import java.sql.PreparedStatement;
          import java.sql.DatabaseMetaData;
          import javax.ejb.CreateException;
          import javax.ejb.EJBException;
          import javax.ejb.SessionBean;
          import javax.naming.Context;
          import javax.naming.InitialContext;
          import javax.naming.NamingException;
          import javax.sql.DataSource;

          import com.sample.ejb.util.SessionAdapter;

          public class SequenceBean extends SessionAdapter {

          /** The query to get the next value from the keys table */
          private static final String selectQuery =
          new StringBuffer("select next_value ")
          .append("from primary_keys ")
          .append("where key_name = ?")

          /** The query to update the next value in the keys table */
          private static final String updateQuery =
          new StringBuffer("UPDATE primary_keys ")
          .append(" SET NEXT_VALUE = ? ")
          .append(" WHERE KEY_NAME = ?")

          public void ejbCreate() throws CreateException {
          // No action required for stateless session beans

          public Integer getNextValue(String keyName) throws SequenceException {
          int returnValue = 0;

          Connection con = null;
          PreparedStatement pstmt = null;
          ResultSet rs = null;
          DatabaseMetaData dmd = null;
          ResultSet table_list = null;
          ResultSet cat_list = null;
          String[] types = {"TABLE"};

          try {
          //Context context = new InitialContext(System.getProperties());
          System.out.println( "SequenceBean: get InitialContext..." );
          Context context = new InitialContext();
          System.out.println("SequenceBean: got context: " + context);
          System.out.println("SequenceBean: looking up the DataSource...");
          DataSource ds =
          System.out.println("SequenceBean: datasource: " + ds);
          //System.out.println("SequenceBean: datasource name: " + ds.getName());
          con = ds.getConnection();
          System.out.println("SequenceBean: got connection: " + con);
          dmd = con.getMetaData();
          System.out.println("SequenceBean: connection product: " +

          try {
          table_list = dmd.getTables(null, null, "%", types);

          // Get the table names
          while (table_list.next()) {
          // Get the table name
          String tableName = table_list.getString(3);

          // Get the table's catalog and schema names (if any)
          String tableCatalog = table_list.getString(1);
          String tableSchema = table_list.getString(2);
          System.out.println("SequenceBean: table in db: " + tableName);
          } // end try...
          } catch (SQLException e) {

          pstmt = con.prepareStatement(selectQuery);
          pstmt.setString(1, keyName);
          System.out.println("SequenceBean: executing query: " + pstmt);
          rs = pstmt.executeQuery();

          if (rs.next()) {
          returnValue = rs.getInt("NEXT_VALUE");

          pstmt = con.prepareStatement(updateQuery);
          pstmt.setInt(1, returnValue + 1);
          pstmt.setString(2, keyName);
          System.out.println("SequenceBean: got keyName: " + keyName);
          } else {
          // Close connections before throwing the exception
          try {
          } catch (Exception ignored) { }
          try {
          } catch (Exception ignored) { }
          try {
          } catch (Exception e) { }
          System.out.println("SequenceBean: Could not obtain a key " +
          "value for the key name " + keyName);
          //throw new SequenceException("Could not obtain a key " +
          // "value for the key name " + keyName);
          } catch (NamingException e) {
          throw new SequenceException("Error getting JDBC " +
          "resources: " + e.getMessage(), e);
          //System.out.println("SequenceBean: Error getting JDBC " +
          // "resources: " + e.getMessage(), e);
          } catch (SQLException e) {
          throw new SequenceException("Error in SQL: " +
          e.getMessage(), e);
          //System.out.println("SequenceBean: Error in SQL: " +
          // e.getMessage(), e);
          } finally {
          try {
          } catch (Exception ignored) { }
          try {
          } catch (Exception ignored) { }
          try {
          } catch (Exception ignored) { }

          return new Integer(returnValue);

          The jbosscmp-jdbc.xml:

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE jbosscmp-jdbc PUBLIC
          "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN"


          <eager-load-group>group name</eager-load-group>






          The ejb-jar.xml:

          <?xml version="1.0"?>

          <!DOCTYPE ejb-jar PUBLIC
          "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"



          This Office bean represents a sample office,
          including its location.



          Connection to the sample database.
          <init-param driver-name="com.mysql.jdbc.Driver"/>
          <init-param user="tom"/>
          <init-param password="password"/>


          This Sequence bean allows entity beans to obtain primary key
          values as if from a sequence.

          <!-- 'Container' or 'Bean' ?? -->


          Connection to the sample database.
          <init-param driver-name="com.mysql.jdbc.Driver"/>
          <init-param user="tom"/>
          <init-param password="password"/>



          the ones who have full access to the EJB