Hey ranchers. I have some questions about CMP & CMR. assume we have the following 2 CMP beans. TeamBean contains the following fields : name and city and its database schema is : NAME , CITY PlayerBean contains id, mail and its database schema is : ID, EMAIL, FK_NAME as you note FK_NAME is a FK to Team schema. now, if I called : player.setTeam(team); the container will manage the relationship and INSERT a value at FK_NAME column, right ? I just want to know this please.
May be it's just quite hard to understand what exactly are you asking. :-)
Can you clarify a bit? Let's talk virtually not about "beans", but about "tables". What will be one table, what will be another? What is the relationship between? On which field?
<a href="http://www.BossTalks.com" target="_blank" rel="nofollow">http://www.BossTalks.com</a><br />Free advices and help for entrepreneurs: from Idea to IPO<br />Software and IT Project Management forum
you will have to create the FK entry before. But then you can set the relation with your setTeam method.
If you want a team be created when inserting a player, you may check if the team exist in the ejbcreate method of the player bean. If not create it and then you can set it.
Things get always more complicated as expected.<br />Author of eBook Hibernate 3 Developer Guide by example<br />Tutorials about Hibernate, EJB, Struts, JSF <a href="http://www.laliluna.de" target="_blank" rel="nofollow">www.laliluna.de</a>
Originally posted by John Todd: player.setTeam(team); the container will manage the relationship and INSERT a value at FK_NAME column, right ?
If you are asking if the container will set the FK_NAME column on the new PLAYER row, the answer is yes. This is precisely what CMR is designed to do: manage your relationships' foreign keys. It also provides navigatability in your finders and beans themselves.