Scenario:
A session bean tracker and 2 entity beans employee and timesheet.Both the entity beans are local EJB objects.Employee has one-many CMR relation with timesheet.
The tracker bean creates a local timesheet instance and passes it to employee.The employee retreives the timesheets collection ,and adds this instance to the collection.
Problem:
If i populate the members of timesheet bean in ejbcreate,i get the error ===>
javax.ejb.EJBException: [EJB:010146]The setXXX method for a cmr-field that is mapped to a primary key may not be called. The cmr-field is read-only.
So i remove the population to ejbpostcreate.However in this case,i get the error===>
In EJB 'TimeSheet', the primary key field 'date' was not set during ejbCreate. All primary key fields must be initialized during ejbCreate.
how can i pass a timesheet instance from tracker to employee and ask it to store it into the timesheets collection.
All beans have CMP.
-
Urgent: ejbcreate and ejbpostcreate (1 messages)
- Posted by: rana nag
- Posted on: July 21 2005 01:40 EDT
Threaded Messages (1)
- Urgent: ejbcreate and ejbpostcreate by sawan parihar on July 25 2005 23:40 EDT
-
Urgent: ejbcreate and ejbpostcreate[ Go to top ]
- Posted by: sawan parihar
- Posted on: July 25 2005 23:40 EDT
- in response to rana nag
In EJB 'TimeSheet', the primary key field 'date' was not set during ejbCreate
You need to set the date dield in the ejbCreate method of the Timesheet class.
In the ejbPostCreate() of employee bean do somethign like this :
InitialContext cntx = new InitialContext();
TimesheetHome timesheetHome = (TimesheetHome )cntx.lookup("TimesheetHome");
Timesheet timesheet= timesheetHome.findByPrimaryKey(pk);
Here you can se the CMR filed(timesheet).
Hope it helps.