0 Replies Latest reply on Nov 20, 2005 1:48 PM by Alexander Rotbart

    How to map cmp bean to database

    Alexander Rotbart Newbie

      Hello, dear stuff!
      I am newbie in EJB, here is my problem description

      1. I use Xdoclet
      2. Using ODBC I created datasource to MsAccess , and it works (tested!).
      I want to work with table called "table1"
      3. I Created CMP Ejb , Lookup returns the object, no any problem at this step
      4. But findByPrimaryKey fails! My table isn't emty, it contains a couple of lines.
      The most strange is the error I got:

      "Find failed: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]
      The Microsoft Jet database engine cannot find the input table or query 'Person'.
      Make sure it exists and that its name is spelled correctly."


      If I rename my table1 to Person - it works!!!!

      ... and the question is how to map EJB to table????

      Ejb jar contains line
      <abstract-schema-name>table1</abstract-schema-name>
      As I understood, this is the place where I refer my EJB to particular table.
      Am I wrong?
      I use eclipce plugin , so maybe it has some "bugs".... Hard to believe,
      but possible?

      My class starts as follows:
      /**
      * @ejb.bean name="Person"
      * display-name="Name for Person"
      * description="Description for Person"
      * jndi-name="ejb/PersonBean"
      * primkey-field = "numberFld"
      * type="CMP"
      * cmp-version="2.x"
      * view-type="both"
      * schema = "table1"
      *
      *
      */
      public abstract class PersonBean implements EntityBean {
      ........



      My ejb-jar as follows

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

      <ejb-jar >

      <![CDATA[No Description.]]>
      <display-name>Generated by XDoclet</display-name>

      <enterprise-beans>

      <!-- Session Beans -->
      <!--
      To add session beans that you have deployment descriptor info for, add
      a file to your XDoclet merge directory called session-beans.xml that contains
      the markup for those beans.
      -->

      <!-- Entity Beans -->

      <![CDATA[Description for Person]]>
      <display-name>Name for Person</display-name>

      <ejb-name>Person</ejb-name>

      DbEjb.interfaces.PersonHome
      DbEjb.interfaces.Person
      <local-home>DbEjb.interfaces.PersonLocalHome</local-home>
      DbEjb.interfaces.PersonLocal

      <ejb-class>DbEjb.ejb.PersonCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Double</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>


      <abstract-schema-name>table1</abstract-schema-name>
      <cmp-field >
      <![CDATA[Getter for CMP Field stringFld]]>
      <field-name>stringFld</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Getter for CMP Field numberFld]]>
      <field-name>numberFld</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[Getter for CMP Field dateFld]]>
      <field-name>dateFld</field-name>
      </cmp-field>
      <primkey-field>numberFld</primkey-field>

      <!-- Write a file named ejb-finders-PersonBean.xml if you want to define extra finders. -->


      <!--
      To add entity beans that you have deployment descriptor info for, add
      a file to your XDoclet merge directory called entity-beans.xml that contains
      the markup for those beans.
      -->

      <!-- Message Driven Beans -->
      <!--
      To add message driven beans that you have deployment descriptor info for, add
      a file to your XDoclet merge directory called message-driven-beans.xml that contains
      the <message-driven></message-driven> markup for those beans.
      -->

      </enterprise-beans>

      <!-- Relationships -->

      <!-- Assembly Descriptor -->
      <assembly-descriptor >
      <!--
      To add additional assembly descriptor info here, add a file to your
      XDoclet merge directory called assembly-descriptor.xml that contains
      the <assembly-descriptor></assembly-descriptor> markup.
      -->

      <!-- finder permissions -->

      <!-- transactions -->

      <!-- finder transactions -->
      </assembly-descriptor>

      </ejb-jar>