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

Reply via email to