• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to use Entity Bean Relationships

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
I am new to the Entity Beans, and found that I really like it.
I was a little confused about the entity beans relationship. Can anyone give me an explanation on what's the correctly or proper way to use it?
Is there any special consideration need to be taken into when designing the database in order to use entity beans and their relationships?
Thanks a lot.
Mike
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's exactly as the relations implemented inside the database. I'll give you the simplest example, about a one-to-one relationship. Let's say you have two tables inside the database: Order and Shipping. One order can have only one Shipping and one Shipping belongs only to one Order. CMR comes into picture for example when loading the Order entity. In BMP, you may choose now between lazy or aggressive loading. Lazy loading means loading a related bean only when you need that data, and aggresive loading means loading all the related data into a single transaction. With CMP lazy loading happens automatically behind the scenes.
You have to keep in mind that the relationships are set inside ejbPostCreate. For example if inside table Order you have to set OrderNumber, CustomerID and ShippingID every time you insert a new Order, you will set first two inside ejbCreate and the ShippingID inside ejbPostCreate (of course, only if you have a relation between Order and Shipment).
These are some benefits of CMR.
Read more about this in Ed Roman's "Mastering EJB 2nd Edition"
[ January 26, 2004: Message edited by: sergiu truta ]
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I too in the Learning stage of EJB.Can u tell me the importance
of ejbPostCreate in elaborate.Why u need to load the shippingID in the
ejbPostCreate.What will happen when u load it in create method itself
and I too have one more question..
Why we need to go for Entity bean.Why we can't use this statefull
session bean and look up the database..

Regards,
Sangeeth
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sangeetha Vasantha:
Can u tell me the importance of ejbPostCreate in elaborate.Why u need to load the shippingID in the ejbPostCreate. What will happen when u load it in create method itself


Use ejbCreate to create the identity of the bean -- its PK and any attributes you consider *essential* to the bean being a valid bean (name, key, etc). You set up all relationships (and any other attributes you need) in ejbPostCreate because in ejbCreate the bean has no PK and thus cannot be involved in relationships.

Originally posted by Sangeetha Vasantha:
Why we need to go for Entity bean.Why we can't use this statefull
session bean and look up the database..


Stateful session beans are tied to the client that created them. Entity beans can be accessed by many clients. As well, there is no such thing as "container-managed persistence for stateful session beans," and thus you'd be SOL unless you wanted to write your own JDBC code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic