After reviewing these comments I think we are making this way more 
complicated than it has to be. As far as I am concerned we should only 
need the relationship stuff in jbosscmp-jdbc.xml for relationships that 
use a relation table (ex. self relation employee/manager, just to 
control the name and fields ) or for primary keys that are composite.

We should avoid creating tables if all possible. I would see only 3 
cases where you need a thrid table
Many to Many
1 to Many (unidirectional. I can not come up with an example but it 
would be valid)
Self referencing entry

Time passes ...

I'm am really trying hard to not have to use this jboss-jdbc.xml ... For 
  composite foreign keys would could also the jdbc method 
getImportedKeys() to figure out composite keys. This would mean the jdbc 
driver would have to support the DatabaseMetaData method and the dba 
would have to use the references in their table definition. We could 
always fall back to the xml file if it did not exsist. So with a good 
jdbc driver we really would only have to create an xml entry if we had a 
specfic relation table we had already predefined.

Maybe I'm foaming at the mouth,  but I feel this is a HUGE feature for 
people writting business apps and it should be as simple as possible. I 
really think this could be simpler for the developers and users.

Comments?



Dain Sundstrom wrote:

> Dave,
> 
> Ok, I see the misunderstanding now.  I thought you were talking about the
> jbosscmp-jdbc.xml file and you were talking about the ejb-jar.xml file.  You
> are correct in that a single relation can only have one cmr field on each
> side of the relationship. From my perspective these are object layer cmr
> fields and not relational level foreign keys.
> 
> To specify how a relationship maps, you need to add a relationships section
> to the jbosscmp-jdbc.xml file.
> 
> <relationships>
> <ejb-relation>
>     <ejb-relation-name>Order-OrderDetail</ejb-relation-name>
>     <foreign-key-mapping>
>         <ejb-relationship-role>
> 
> <ejb-relationship-role-name>Order-has-OrderDetail</ejb-relationship-role-nam
> e>
> 
>             <foreign-key-fields/>
> 
>         </ejb-relationship-role>
> 
>         <ejb-relationship-role>
>             <ejb-relationship-role-name>OrderDetail-
> belongsTo-Order</ejb-relationship-role-name>
> 
>             <foreign-key-fields>
>                 <foreign-key-field>
>                     <field-name>order_oid</field-name>
>                     <column-name>order_oid</column-name>
>                 </foreign-key-field>
>             </foreign-key-fields>
> 
>         </ejb-relationship-role>
>     </foreign-key-mapping>
> </ejb-relation>
> </relationships>
> 



> I'm not sure that this will work.  The code may try to create a table with 2
> order_oid columns because you trying to reuse a column mapped to a cmp field
> to store a relation foreign key.  You may need to create the table by hand.
> I need to check this, because I think it will be a common mapping.
> 
> I'd also like to take a moment to explain why the foreign key field is
> generated the way it is.
> 
> I can't just a cmp field has the same name as the pk related ejb becasue of
> the case of a self related entity such as an employee/manager relationship
> in the employee object. I always have to prepend the ejb name of the related
> ejb to the fk, because it is common to have all beans to have a generic pk
> name such as oid (I do this).
> 






_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to