Entity relationship & legacy db tables
cwele Jan 16, 2003 6:52 PMI have existing (legacy) DB schema (for simplificity, just two tables, CustomerEJBTable & AccountEJBTable):
CustomerEJBTable:
-------------------
Account_pmPrimaryKey integer,
userid string
AccountEJBTable:
-----------------
PMPrimaryKey integer,
Status string
So, I do not want to allow JBoss to create db tables.
At the database level, there is no strictly defined foreign key constraint,
but, in fact, CustomerEJBTable.Account_pmPrimaryKey
points to the primary key of the AccountEJBTable
Further, in the customerEJB, I have one cmr field, named 'account'.
I want to establish one-to-one unidirectional relationship between customerEJB and accountEJB
Here is extract from ejb-jar.xml & jbosscmp-jdbc.xml:
ejb-jar.xml
-------
<ejb-relation>
<ejb-relation-name>customerEJB-AccountEJB</ejb-relation-name>
<ejb-relationship-role>
customerEJB
<ejb-relationship-role-name>CustomerEJB</ejb-relationship-role-name>
One
<relationship-role-source>
customerEJB
<ejb-name>CustomerEJB</ejb-name>
</relationship-role-source>
<cmr-field>
accountEJB
<cmr-field-name>account</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
accountEJB <ejb-relationship-role-name>AccountEJB</ejb-relationship-role-name>
One
<cascade-delete />
<relationship-role-source>
accountEJB
<ejb-name>AccountEJB</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
jbosscmp-jdbc.xml
------
<ejb-relation>
<ejb-relation-name>customerEJB-AccountEJB</ejb-relation-name>
<foreign-key-mapping />
<ejb-relationship-role>
<ejb-relationship-role-name>CustomerEJB</ejb-relationship-role-name>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>AccountEJB</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>pMPrimaryKey</field-name>
<column-name>ACCOUNT_PMPRIMARYKEY</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
--------
And now, in the CustomerEJB.ejbPostCreate(), I have following code,
which just creates AccountEJB entity:
InitialContext ic = new InitialContext();
AccountLocalHome alh = (AccountLocalHome)
ic.lookup("java:comp/env/ejb/local/customer/account");
AccountLocal account = alh.create(AccountLocalHome.Active);
setAccount(account);
// where is 'account' - one cmr field in the CustomerEJB
At this moment, please take a look at following line from my JBoss
server.log file:
INSERT INTO ACCOUNTEJBTABLE (PMPRIMARYKEY, STATUS, CustomerEJB_account)
VALUES (?, ?, ?)
Please, notice last column in the insert statement: CustomerEJB_account
Q1: This mysterious column does not exists in AccountEJBTable, so, why
JBoss attempts to store some value in this column ?
Of course, my JDBC driver raises SQLException:
Column unknown
CUSTOMEREJB_ACCOUNT
It looks like problem with jbosscmp-jdbc.xml, or not ?
Q2: What I should to do, to avoid this problem ? I cannot believe that I must to extend my database tables with this strange column names, and unknown types :((
By the way, I have a lot of legacy database tables....
----
-thanks in advance ....