in a method of my session bean ,i use a loop to update several entity beans.firstly,I get the entity bean by ejb home's findByPrimayKey method,then get the value object ,set the value oject properties,and then set the value object into ejb remote interface.my problem is that i always got the last entity bean updated.
can anybody give an answer?
thanks.
-
I only get the last entity bean updated in a loop (3 messages)
- Posted by: shuhu hao
- Posted on: October 12 2001 13:47 EDT
Threaded Messages (3)
- I only get the last entity bean updated in a loop by sheetal P on October 12 2001 14:57 EDT
- I only get the last entity bean updated in a loop by Victor Jan on October 13 2001 03:15 EDT
- I only get the last entity bean updated in a loop by shuhu hao on October 15 2001 05:43 EDT
- I only get the last entity bean updated in a loop by Victor Jan on October 13 2001 03:15 EDT
-
I only get the last entity bean updated in a loop[ Go to top ]
- Posted by: sheetal P
- Posted on: October 12 2001 14:57 EDT
- in response to shuhu hao
After you get a handle to the home object, start the loop, for each unique key, loop through and findByPrimaryKey. findByPrimaryKey will return you the Remote Object. Set the appropriate values using Setters. This internally would kick off ejbStore everytime and update all your beans.
Eg:
//get a handle to the home object
final AlertHome alertHome = (AlertHome)PortableRemoteObject.narrow(remoteRef, AlertHome.class);
//for each of the unique id
for (int i=0; i<alertID.length; i++) {
mkey = new AlertKey(alertID[i]);
//create a new primarykey
System.out.println("*************alert key to find by is " + alertID[i]);
alert = (Alert)alertHome.findByPrimaryKey(mkey);
//findByPrimaryKey returns a remote object
alert.setMyAlertProfileId(null);
//set the necessary values, this will update each entity bean -
I only get the last entity bean updated in a loop[ Go to top ]
- Posted by: Victor Jan
- Posted on: October 13 2001 03:15 EDT
- in response to sheetal P
Eg:
//get a handle to the home object
final AlertHome alertHome = (AlertHome)PortableRemoteObject.narrow(remoteRef, AlertHome.class);
//for each of the unique id
for (int i=0; i<alertID.length; i++) {
mkey = new AlertKey(alertID[i]);
//create a new primarykey
System.out.println("*************alert key to find by is " + alertID[i]);
//WHETHER YOU SHOULD CREATE A NEW VARIABLE FOR EVERY ALERT.
ALERT alert = (Alert)alertHome.findByPrimaryKey(mkey);
//findByPrimaryKey returns a remote object
alert.setMyAlertProfileId(null);
//set the necessary values, this will update each entity bean -
I only get the last entity bean updated in a loop[ Go to top ]
- Posted by: shuhu hao
- Posted on: October 15 2001 05:43 EDT
- in response to Victor Jan
thank jan.
i review your example and find out that the difference between yours and mine :
(1) yours declare the remote interface variable in the loop,
and mine out the loop.
(2) yours set the properties of ejb directly while mine set it via a value object.
I don't know whether one of the differnce cause the problem