1 Reply Latest reply on Dec 19, 2002 3:46 PM by Andy

    How to map EJB names to DB table names of my choosing?

    fumeishi Newbie

      Hello everyone, I'm a newbie.

      Can anyone tell me how to map EJB names to db table names of my choosing?

      Background:

      Using Oracle9i and JBOSS 3.0.2 to implement a J2EE Web application. Until recently, I've been using mySQL, but just started my efforts to migrate to Oracle.

      On startup, my web app creates a number of tables via JDBC. It's able to do so without a problem under mySQL, but runs into a problem with Oracle:

      java.sql.SQLException: ORA-00972: identifier is too long.

      I've since learned that this is due to a limitation of Oracle where schema objects must be <=30 characters in length. And, in fact, I have three EJBs whose names exceed that, so I'm happy to understand the nature of my problem there.

      I don't know whether or not that 30 char limit is insurmountable, but I'd like to fix the problem by designating table names of my choosing. I know that with weblogic, for example, there's an XML file (weblogic-cmp-rdbms-jar.xml) that allows me to make this kind of mapping. Can anyone tell me if there's a JBOSS equivalent?

      Thanks a lot in advance.

        • 1. Re: How to map EJB names to DB table names of my choosing?
          Andy Newbie

          Hi,

          with JBoss you need a file jbosscmp-jdbc.xml

          Here's a snippet of the types of things to include ... (look in the DTD file referenced for the definition).


          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE jbosscmp-jdbc PUBLIC
          "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN"
          "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">

          <jbosscmp-jdbc>

          java:/DefaultDS
          <datasource-mapping>Hypersonic SQL</datasource-mapping>


          <enterprise-beans>
          <!-- AccountBean DB table mapping -->

          <ejb-name>AccountBean</ejb-name>
          <create-table>true</create-table>
          <remove-table>false</remove-table>
          <table-name>WebShopAccount</table-name>
          <cmp-field>
          <field-name>id</field-name>
          <column-name>Id</column-name>
          <jdbc-type>VARCHAR</jdbc-type>
          <sql-type>VARCHAR(40)</sql-type>
          </cmp-field>
          <cmp-field>
          <field-name>name</field-name>
          <column-name>Name</column-name>
          <jdbc-type>VARCHAR</jdbc-type>
          <sql-type>VARCHAR(50)</sql-type>
          </cmp-field>

          </enterprise-beans>
          </jbosscmp-jdbc>

          So you can specify the DB table name, and the column names, the SQL types (this is optional), etc.

          HTH