Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Mali Jainukul   on Nov 23 In Java Category.

  
Question Answered By: Brandon Tucker   on Nov 23

I got your whole point. but one thing to mention is that, it seemd like you had corresponding accessor methods for foreign keys in your 4th entity bean. because at the end you had :

fo.setFirst(f);
fo.setSecond(s);
fo.setThird(t);

OK, but as you may have noticed, the 4th table  had a 1-n relation with each of the other 3 tables.(4th table is CHILD while the other end is the PARENT).

As I encountered and examined in EJBs like this, the child entity bean  DO NOT have any accessor method  for the foreign keys, instead we define a business method in the parent as:


public void addChild(LocalChild child) {
try {
Collection children = getChildren();

children.add(child);
} catch (Exception ex) {
throw new EJBException(ex.getMessage());
}
}

now, we can use this method in the facade session  bean like this:

public void createChildInParent(childObject, PK) {
try {
LocalParent parent = parentHome.findByPrimaryKey(PK)
LocalChild child = childHome.create(...no FK accessor method...)
parent.addChild(child);
} catch (Exception ex) {
throw new EJBException(ex.getMessage());
}
}

And again, while we have no accessor method for the foreign keys.
what I don't know is that what happens if the CHILD entity relates to 3 instead of one.

BTW, please, if you know, convince me about one of these 2 approaches, i mean yours and what i have encountered.

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Simple EJB Design Or get search suggestion and latest updates.


Tagged: