Do you find the M-H pattern worthwhile in practice? More often than not, the
presentation layer initiates the Bar access with respect to a non-EJB form bean or
data object rather than the EJB itself, if for no other reason than to avoid network
round trips (cf. http://theserverside.com/patterns/thread.jsp?thread_id=79). In that
case, the Bar access alternatives are:
FooData fd = foo.getData();
BarData bar = null;
if (fd.getBarId() != 0) {
foo = getFooHome().findByPrimaryKey(new Integer(fooId));
Bar bar = foo.getBar();
bd = bar.getData();
}
vs.
FooData fd = foo.getData();
BarData bar = null;
if (fd.getBarId() != 0) {
Bar bar = getFooHome().findByPrimaryKey(new Integer(barId));
bd = bar.getData();
}
The second form is slightly simpler than the first and considerably more efficient.
Adam Young wrote:
> The Monson-Haefel book suggests using the foreign keys as properties of
> the beans, and then have accessors that get the related objects.
> if foo
> ...
> int getBarId()
> void setBarId(int id)
> Bar getBar();
> ..
>
> and then in the FooBean:
> private Bar bar;
> public Bar getBar(){
> if (null == bar){
> foo = getBarHome().findByPrimaryKey(new Integer(foodId));
> }
> return foo;
> }
>
> I am ignoring exception handling and the accessor for getBarHome.
>
> Is this the way that most people are handling relationships?
>
> Kar YEOW wrote:
>
> >The relationship stuff is in EJB2.0 and it is still in DRAFT. It is not yet
> >supported in JBOSS.
> >Kar
> >----- Original Message -----
> >From: "Richard Kasperowski" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Sent: Tuesday, June 19, 2001 7:34 AM
> >Subject: [JBoss-user] How to specify relationships between CMP EJBs?
> >
> >
> >I'm trying to understand how container managed persistence make this
> >happen. I have two EJBs like so:
> >
> >-----
> >public interface Foo extends EJBObject {
> > Long getId() throws RemoteException;
> > void setId(Long param) throws RemoteException;
> > String getName() throws RemoteException;
> > void setName(String param) throws RemoteException;
> > Bar getBar() throws RemoteException;
> > void setBar(Bar param) throws RemoteException;
> >}
> >
> >public interface Bar extends EJBObject {
> > Long getId() throws RemoteException;
> > void setId(Long param) throws RemoteException;
> > String getName() throws RemoteException;
> > void setName(String param) throws RemoteException;
> >}
> >-----
> >
> >The idea here is that a Foo has a Bar. The Bar must already exist.
> >
> >I want this to work through CMP. I can't quite figure out how to tell
> >JBoss that there's a relationship between Foo and Bar. I've been
> >playing around with the tags "relationships" and "cmr-field", but I
> >haven't been able to get it right.
> >
> >Does anyone have an example that I could follow?
> >
> >Thanks,
> >
> >--
> >Richard Kasperowski (mailto:[EMAIL PROTECTED])
> >Tel: 617-576-1552, Fax: 617-576-2441
> >http://www.altisimo.com/
> >
> >
> >_______________________________________________
> >JBoss-user mailing list
> >[EMAIL PROTECTED]
> >http://lists.sourceforge.net/lists/listinfo/jboss-user
> >
> >
> >_______________________________________________
> >JBoss-user mailing list
> >[EMAIL PROTECTED]
> >http://lists.sourceforge.net/lists/listinfo/jboss-user
> >
> >
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user
--
Fred Loney
Spirited Software, Inc.
[EMAIL PROTECTED]
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user