• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB2.0 CMP - with a BMP cmr field

 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can an EJB2.0 CMP entity bean have a CMR field that is a BMP entity bean and vice-versa?
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vish,
I don't see any reason for preventing you of doing that. BMP vs CMP is a question of implementation, while CMR fields refer to a component interface, where the distinction BMP vs CMP doesn't exist. Moreover, BMP and CMP entity beans are compatible at the implementation level too : same interface implemented, same callbacks (even the ejbCreate() BTW).
Regards,
Phil.
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy -- unfortunately, you cannot have a CMR relationship with a BMP bean... a CMR relationship means demands that *both* sides of the relationship are managed by the Container, so there's just no way you can do it. Although as Phillipe said, a CMR field is the component interface of an entity bean, and there's nothing in that interface that explicitly makes it a CMP vs. BMP bean, Bean Law (i.e. the spec rules) insists that one bean can have a relationship only with other CMP beans.
Unless the Container is "in charge" of both sides of the relationship (and it doesn't really matter if it is uni- or bi-directional), it would not be able to maintain referential integrity, or handle things like cascading deletes.
So, just remember that CMR = Container-Managed Relationship and Container-Managed Relationship means you MUST use Container-Managed Persistence on BOTH sides of the relationship. Both partners must use CMP.
The Container is a control freak
Now, that doesn't mean that you can't mix and match CMP and BMP beans in an app--only that they can't be in an official CMR relationship with one another.
cheers,
Kathy
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Kathy ! You just made one more demonstration of the big difference between knowing a bit and mastering...
What's nice on this forum is that even when the exam is behind you, you still learn a lot !
Best,
Phil.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kathy and Phillipe,
Another good thing about this forum is, I can expect replies on a Sunday evening too...

Cheers,
Vish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic