• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to code: A->B using BMP

 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am using BMP because I have created a composite entity. I also am populating one of the entity beans with data obtained from a service.

I have three entity beans that I want to connect together. Is it better to store an entity pk or a reference to the entity?

Example:

EntityBeanA{
EntityBeanB b;
}

or

EntityBeanA{
entityBeanBPrimaryKey bPk;
}

Before updating EntityBeanB, should the code be:
A.getB() to get B?

Thanks in advance.

-Saha
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use references. Let's step back and take a look.

class EntityA implements EntityBean
{
private EntityB childBean;
....
}

If you plan to pass the references then you must have instantiated both the bean in the accessing program by these steps
- find and load EntityA with a primary key
- read the foreignkey from the EntityA to the calling program
- use this foreignKey to load EntityB at the calling program
- pass the references of EntityB back to EntityA

Other way is
- find and load EntityA with the primary key
- EntityA before exiting load() method find and loads the EntityB

You don't want to store the EntityB through reference unless you have access to the referenced objects already.
 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I will implement as primary key, then look it up lazily.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic