Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMR gone in EJB 3.0

 
Paul Eggerling-Boeck
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just read something on Sun's website that mentioned that the EJB 3.0 spec dropped support for CMR.

I'm looking into using EJB, but I want to know for sure what this statement means.

If I have two entity beans, Order and LineItem and my Order object has a List of LineItem objects, how will the elimination of CMR affect this relationship?

Thanks!

Paul
 
Jon Wetherbee
author
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul-
What this means is EJB 3 no longer maintains the relationship field at the other end of the relationship when one end is updated. For instance, in a 1:* relationship, if you insert into the collection end, the single-value end doesn't get updated automatically on the entity, and vice-versa. In EJB 2.x, the relationship field on the other end would automatically get wired up for you, which was convenient but incurred a huge overhead for the persistence manager. You can emulate the EJB 2.x behavior by modifying your entity code (or using a code generator to build your entities).

A common pattern is to define add/remove methods to accompany the Collection field, and modify the set method on the single-value end. In both cases, the idea is to update the field at the other end of the relationship.

The bottom line is relationships between JPA entities (successors to entity beans) are still supported, but the automatic wiring feature in EJB 2.x CMR fields is no longer there.

Regards,
Jon

Beginning EJB 3 Application Development: From Novice to Professional
 
Paul Eggerling-Boeck
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jon. That sounds pretty much like what I'm used to doing in a Hibernate environment.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Eggerling-Boeck:
Thanks Jon. That sounds pretty much like what I'm used to doing in a Hibernate environment.



"pretty much"? actually more "exactly" like.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic