EJB relations an PK fields
apurrichus Aug 12, 2004 10:38 AMHi, I am Using Container Managed Persistence with JBOSS, and I have a problem when i try to insert a record on an ejb that its primary key makes reference to another EJB, i've mapped the field as CMP, but when i set the ejb-relation the sql is corrupt....
I have the next database Model:
IFX_PRICING ------------------------ ID NOT NULL VARCHAR2(15) ---> pk CUSTOMER NUMBER(8) TOTAL NOT NULL NUMBER(25,13) CREATION_DATE NOT NULL DATE IFX_PRICINGSERVICE --------------------------------- PRICING NOT NULL VARCHAR2(15) -->PK FK from IFX_PRICING SERVICE NOT NULL NUMBER(3) -->PK TOTAL NOT NULL NUMBER(25,13)
Then I map the CMP Entity beans, i set the access Methods for PricingBean like:
// Access methods for relationship fields
public abstract Collection getPricingServices();
public abstract Collection getPricingServiceFeatures();
and I define my relations as:
<ejb-relation> <ejb-relation-name>Pricing-PricingService</ejb-relation-name> <ejb-relationship-role> <multiplicity>One</multiplicity> <relationship-role-source> <ejb-name>Pricing</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>pricingServices</cmr-field-name> <cmr-field-type>java.util.Collection</cmr-field-type> </cmr-field> </ejb-relationship-role> <ejb-relationship-role> <multiplicity>Many</multiplicity> <relationship-role-source> <ejb-name>PricingService</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>pricing</cmr-field-name> </cmr-field> </ejb-relationship-role> </ejb-relation>
First, If I don't define the <cmr-field-name>pricing</cmr-field-name> i get :
Could not create entity:java.sql.SQLException: ORA-00904: "PRICING_PRICINGSERVICES": invalid identifier
Printing the sql script:
[org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.PricingService] Insert Entity SQL: INSERT INTO IFX_PRICINGSERVICE (PRICING, SERVICE, TOTAL, Pricing_pricingServices) VALUES (?, ?, ?, ?)
I don't understand why if I only want to define a unidirectional relation...
Second, If I set the field on my deployment descriptor (bidirectional), when I try to insert a record on my PRICINGSERVICE EJB, i get :
Could not create entity:java.sql.SQLException: ORA-00957: duplicate column name
Printing the sql script:
[org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.PricingService] Insert Entity SQL: INSERT INTO IFX_PRICINGSERVICE (PRICING, SERVICE, TOTAL, Pricing_pricingServices) VALUES (?, ?, ?, ?)
I guess is for the pk, that is cmp and is defined as cmr too, when i define my relationship, If i omit the ejb-relation I can insert a new record, but I need to get all details of my pricingservices associated to my Pricing.... (I don't want to do it with a select method)
someone answer me that i've just discovered why experts recomends not to use composite primary key with ejb relations, but form me this is weird... because it would be limiting the design..