We've actually gone with a hybrid approach.  All of our objects provide two methods 
for setting a reference. The first method includes the id of the referenced object in 
the argument list.  The second includes the actual object reference in the argument 
list.  Something like this:

public class Order{
  public void setCustomer(long customerId){...}
  public void setCustomer(Customer customer){...}
  public Customer getCustomer(){...}
}

Internally, we track the method that was last used to set the reference, either "by 
value" or "by object".

The getter routine checks to see how the reference was last set.  If it was last set 
"by value", then we load the referenced object from the database and set the "last 
set" method to "by object", since we now have the actual object.  

All of our objects implement the PersistenceBrokerAware interface.  In the beforeStore 
method, we check to see how the reference was last set.  If it was last set "by value" 
(setCustomer(long)), then we invoke a routine that will retrieve the actual object 
reference.

Ron Gallagher
Atlanta, GA
[EMAIL PROTECTED]

> 
> From: Charles Anthony <[EMAIL PROTECTED]>
> Date: 2003/03/04 Tue PM 12:28:57 EST
> To: 'OJB Users List' <[EMAIL PROTECTED]>
> Subject: RE: Anybody else have this problem?/Feature Idea
> 
> Hi,
> 
> Developer should only ever set foo, and should never set fooId. 
> 
> OJB manages all foreign keys.
> 
> In our app, we don't generate setters for any id fields (primary or
> foreign), and we only have a getter for the PK. Therefore, the developers
> find it much harder to fiddle with the keys.
> 
> Cheers,
> 
> Charles.
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to