Avatar billede asgaut Nybegynder
14. maj 2005 - 17:21

CMR problem

Hi,

I'm creating an enterprise application using EJB 2.0, CMP 2.0, MySql and WebLogic 8.11. I'm using JBuilder 2005 as an IDE.

I've created a cmr relationship between a local entity bean "Category" and "Product". It is a one-to-one relationship. The field for connecting the two beans is categoryId, which is the primary key in Category and just a normal field in Product (but is going to be used as a foreign key).

They way I created the beans, was to import the database schema into JBuilder, marked the following tables I wanted to use, and clicked “create cmp 2.0 entity bean”. It then creates all the code including interfaces and xml.

When setting up this in JBuilder, everything seems to be ok. But when I try to compile the project, I get this message:

"WebShopEar.jar": Role 'CategoryRelationshipRole' of relationship 'product-category' contains an invalid key-column value of 'category_id'. The key-column must specify a primary key column in the related bean. However, there is no primary key column named 'category_id' defined in the related bean 'Product' or else 'category_id' is not being recognized due to case mismatch.

From weblogic-cmp-rdbms-jar:

<weblogic-rdbms-relation>
    <relation-name>product-category</relation-name>
    <weblogic-relationship-role>
      <relationship-role-name>CategoryRelationshipRole</relationship-role-name>
      <relationship-role-map>
        <foreign-key-table>category_tbl</foreign-key-table>
        <primary-key-table>product_tbl</primary-key-table>
        <column-map>
          <foreign-key-column>category_id</foreign-key-column>
          <key-column>category_id</key-column>
        </column-map>
      </relationship-role-map>
    </weblogic-relationship-role>
  </weblogic-rdbms-relation>


From ejb-jar:

<ejb-relationship-role>
        <description>category</description>
        <ejb-relationship-role-name>CategoryRelationshipRole</ejb-relationship-role-name>
        <multiplicity>One</multiplicity>
        <relationship-role-source>
          <description>category</description>
          <ejb-name>Category</ejb-name>
        </relationship-role-source>
      </ejb-relationship-role>

Description of the tables

Product:
Field Type Null Key Default Extra
product_id int(11)  PRI 0 
product_name varchar(50) YES  NULL 
price double(6,2) YES  NULL 
category_id int(6) YES  NULL 
product_code varchar(20) YES  NULL

Category:
Field     Type Null Key Default Extra
category_id int(6)  PRI 0 
category_name varchar(50) YES  NULL 

CMR fields from the product bean:
public abstract void setCategory(Category category);
public abstract Category getCategory();

CMP fields for categoryId from the product bean:
public abstract void setCategoryId(String categoryId);
public abstract String getCategoryId();

CMP fields for categoryId from the category bean:
public abstract void setCategoryId(String categoryId);
public abstract String getCategoryId();


Appreciate all help!

regards,

Asgaut
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester