• Post Reply Bookmark Topic Watch Topic
  • New Topic

Iam having a doubt in ejbCreate and ejbPostcreate() method  RSS feed

 
Vasantha Prabha
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Iam leaving EJB.Iam having a doubt in that like
do we need ejbpostcreate() for eachejbcreate() method ??
Regards,
Sangeetha
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need an ejbPostCreate() for each ejbCreate() because in case you have a relationship this must be set inside ejbPostCreate(). If you are thinking now "but why do I have to have it if I don't implement any relationship?", it's pretty obvious that the SUN engineers could not make "some" specification for "some other" cases. The specifications are general and should include all the cases. So if you don't implement any relationship you simply have an empty ejbPostCreate() with the same signature as ejbCreate().
 
Vasantha Prabha
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can please explain me what type of relationship will be provided in the
ejbpostcreate() method of a paticular ejbcreate() method.
Regard,
Sangeetha
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example you have two beans: Company and Employee in a 1 to N relationship (a company may have many employees). In the Employee table you have a field like "Company_PK". Here you could use a CMR (Container Managed Relationship) and for example when saving a new employee, you have to set a company to which that employee belongs to. So:
1) in ejbCreate() you save all the necesary data for the employee
2) in ejbPostCreate() you save the company (not as a BigDecimal/Double or whatever you use!) as a CompanyLocal:

setCompany(companyLocal);
Read about CMR and this will clear out.
hope this helps
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!