Sorry, here is the attached project I mentioned above.
You won't be able to make a mapping for that table structure because it uses a not-null foreign key field. I don't know why wrox would suggest this type of mapping as it is very dependent on the server implementation of CMP 2.
You will have to be flexible, and remove the not null constraint until this feature is implemented.
Also you getting the errors because your table mapping in jbosscmp-jdbc.xml file is wrong (I haven't looked at it, but it's wrong).
Thanks so much for responding, Dain. The create statements are my own, not wrox's (wouldn't want to make them look bad). I used their name because the attached code was oringinally theirs (I've modified it slightly).
I did read in this forum that the foreign key field cannot be null as of yet. I'm happy to modify it accordingly but MySQL threw an error when I removed the "not null" statement. Can you suggest a statement that MySQL will accept?
Regarding jbosscmp-jdbc.xml, I agree. I'm sure I've got it wrong. I've read through this forum quite a bit but just don't seem to understand the solution (I've also purchased your documentation). Any help you can give me with this file would really be great. Sorry to be asking, I know you've done quite a bit of that in this forum.
Still no luck with jbosscmp-jdbc.xml.
After re-reading Dain's "for-pay" docs and examples I've modified my code slightly but with no impact on the problem. However I think the key-field elements in this version do a better job of modeling the REFERANCES clause of my SQL foreign key declaration.
I noticed in the examples that foreign key columns are not mapped as cmp fields (this seems strange since primary key columns are). As a result, I've removed the cmp entries and java code that mapped my foreign key field. Again, I haven't impacted the problem with these changes so any help is greatly appreciated.
I was unable to attach the whole project so here is an excerpt from jbosscmp-jdbc.xml:
This is a ref. to the primary key attribute in OrderEJB2
This is a ref. to the order_ID clomun of the wrox_address table. This column was assigned a foreign key reference to wrox_order.order_ID
However, I did come up with a create statement that both allows a null foreign key and is acceptable to MySQL. It seems the foreign key field must be set to unique when null is allowed:
create table wrox_address(order_ID bigint,
address_ID bigint not null,
primary key (address_ID),
foreign key (order_ID)
You just need to drop the not null from the order_ID column. Try the following:
create table wrox_address( order_ID bigint, address_ID bigint not null, street varchar(17), city varchar(17), state varchar(17), zip varchar(17), foreign key (order_ID)REFERENCES wrox_order(order_ID), primary key (address_ID) ) type=innodb;
Dain, thanks for responding and welcome back. Although the MySQL create statement is no longer an issue I've had no impact on the real problem. Again, no matter how I modify jbosscmp-jdbc.xml I always get "Column not found: Unknown column 'shipAddress' in 'field list'
" at run time. All my previous posts are still relevant. I can really use some help with this.
I have exactly the same problem, i have a 1-* relationship between two entities.
What I don't understand is that the same code runs fine on Weblogic 6.1, but it doesn't with Jboss 3.0 RC3.
I always get the Column not found Exception.
I keep on changing the jbosscmp-jdbc.xml but nothing, it is really frustrating.
I was able to make a little headway by removing the foreign-key-mapping tag (it's no longer required) from jbosscmp-jdbc.xml thereby allowing my ejb-relationship-role tags to be directly under ejb-relation. This tag appears to suppress everything within. I think it's the reason my constant fiddling with the key-field tags had no impact on my problem.
My new runtime error states that JBoss expected two columns with the same name when my table only has one. Any ideas?
I am merely a beginner, but I think your problem is that you got the mapping in jbosscmp-jdbc.xml reversed. I am not familiar with the semantics involved, but I think they require that you map the primary key of the entity bean represented by the current role in the relationship (the order bean in your case) to the relevant field of the bean represented by the opposite role (the address bean).
So I suggest you try the following:
<key-fields> <!-- <foreign-key-fields> -->
Don't forget to delete the field orderID from the list of cmp-fields in AddressEJB since it is now a cmr-field. Adjust ejb-jar.xml if necessary, though I doubt this should prove so.
I think what causes the confusion is that ejb-jar.xml describes the beans' view of the relationship (pointing from order to address), whereas jbosscmp-jdbc.xml endorses the database's view of the same relationship, in your case pointing from address to order. It's reversed.
Please let me know if this helps.
I modified my jbosscmp-jdbc.xml wut i still have the same error:
Column not found: Unknown column 'department' in 'field list';
I seems we are a lot experiencing the same problem, the RC3 treats CMR fields as CMP fields, so you get this exception saying that the column (corresponding to you CMR field name) doesn't exist.
Again, I'm running the same code, same ejb-jar.xml on Weblogic 6.1 without any problem.
there is an error in my example. Make the first <foreign-key-mapping> a <foreign-key-mapping/> and drop the </foreign-key-mapping> at the end.