I've encountered a serious limitation regarding CMP2 in JBoss3.0.0beta . I've tried to look at the forums but I've not found anything useful. I hope to have made a mistake!
My problem is concerned with relationships mapped in an existing database, specifically about foreign keys names.
To simplify the example suppose we have 2 tables ORDERS (with a primary key column, ID) and LINES (with a pk ID and a foreign key ORDER_ID referencing ORDERS.ID). We want to implement 2 CMP Entity Beans related to those tables, OrderBean and LineBean. Using jbosscmp-jdbc descriptor it's easy to map a cmp-field in its appropriate column in the DataBase, for example:
Now we want to realize a relationship between the beans. In my opinion this is NOT possible!
In fact defining a relationship in ejb-jar is quite simple. For example:
With this, OrderBean is provided with a new field called orderLines wich is a Collection of the related LineBeans.
But whenever an ejbLoad is invoked by the container on a LineBean, an SQL error arises. The issue is that the SQL statement generated by the container is not correct! The SELECT part has a list of all columns of LINES table that we have mapped in the <cmp-field> tags for that Bean (and this is correct) but a new column is added: its name is order. This column is not really defined in the LINES table.
The problem is that JBoss uses the cmr-field name defined in ejb-jar as the name of the column (the foreign key) in LINES referencing ORDERS table. But this is not a correct behaviour!
I've tried in many ways to solve the problem, studying jbosscmp-jdbc DTD but there's no way to tell JBoss that the cmr-field order map to the column name ORDER_ID!
A syntax similar to <cmp-field> would be very useful but is not allowed in the DTD.
Can someone help me solve this problem? What's wrong in my assertions?