This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes need help with CMR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "need help with CMR" Watch "need help with CMR" New topic
Author

need help with CMR

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

I have two entity beans: PlayerBean and TeamBean.
the realtionship between these beans is : one to many (many players to one team).
I am using CMP 2.0 model and the relationship is bidirectional.
the fields of Team table in the database are :
teamname, teamcity
the fields of Player table in the database are:
pid, pname, psalary, pteam (pteam is a string and it serves as a FK).
in the PlayerLocal interface I wrote :
All the codes are inspired from Mastering EJB

in the PlayerBean I wrote:

using J2EE RI, I don't persist the pteam..
are there any things wrong with this design ?
if there is a better way to perform this realtionship please tell me.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi John

using J2EE RI, I don't persist the pteam..

What error you are getting?
Here are my observations for your code,
1. In your first ejbCreate() I don't see setTeam(LocalTeam) call even though you pass the LocalTeam object in there
2. I have not called one ejbCreate() from another so far. I guess it would be better if you call create() from the second ejbCreate()...Though that should not be creating problem for you...
Please provide more input on your problem.
Regards
Maulin
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

1. In your first ejbCreate() I don't see setTeam(LocalTeam) call even though you pass the LocalTeam object in there

Mastering EJB don't do this.
if I called setTeamLocal from ejbCreate, then how the container will filed the pteam field value (in the database) ?
there is something I don't understand:
Player table has a pteam field(String)
in my PalyerBean I have a playerTeam field which is a relation field (the container will not persist it).
so when calling setPlayerTeam(TeamLocal) from the ejbCreate method, how the container will store a value in the database ??
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi John

so when calling setPlayerTeam(TeamLocal) from the ejbCreate method, how the container will store a value in the database ??

Exactly for that reason we have CMR It will know what to update in the table for Player when you do setPlayerTeam()...
Try it and see if it works for you.
Regards
Maulin
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: need help with CMR