I'm having some problems getting a 1-1 relationship between 2 tables using JBoss CMP. The 1-1 relationship is between USERS and CUSTOMERS table. CUSTOMERS.EMAIL is a foreign KEY to USERS.USERNAME, which is also the PK of USERS table ... simple as that.
Now when I map this to DB colums in jbosscmp-jdbc.xml, I could not find a way of how to tell JBoss to use the EMAIL column as the foreign key. I have this as ...
<ejb-relation>
<ejb-relation-name>User-Customer</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>one-CustomerEJB@user-Has-UserEJB</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>one-UserEJB@Customer-Has-CustomerEJB</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>username</field-name>
<column-name>username</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
IT seems to assume that it will create a new column on the CUSTOMERS table called CUSTOMERS.USERNAME to establish the relationship.
When I let it create the tables automatically, it adds a USERNAME column on CUSTOMERS which is not how I want it to be. My database is already in place and I cant change the database structures, so I need to use the EMAIL column as the foreign key. How can I tell JBoss to use this as the FK ?
i think i solved my problem, i had some confusion on "column_name". i thought it was the db column of the "field name", but it's actually the db column of the foreign key in the other table.