You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Ian Hunter <Ia...@inovis.com> on 2004/06/04 15:07:19 UTC

Question about OJB references and manually setting foreign keys (Struts app)

I'm pretty new to OJB, so be gentle. I'm working on a Struts app, using
the PB API, and I have a "Customer" object with an "Account Manager"
reference to a "User" object.  

For instance, something like:

public Class User {
	public int getId();
	public String getName();
}

Public Class Company {
	public int getId();
	public String getName();
	public int getAccountManagerFK();
	public User getAccountManager();
}

For sake of convenience, I have a reference-descriptor within the
Company class-descriptor with auto-retrieve set to true.  I had
originally turned on auto-update as well, until I realized that if I
just wanted to link the Customer to a new Account Manager, I would
actually have to load the corresponding User record from persistence and
call "someCompany.setAccountManager (someUser)" or something to that
effect to get OJB to "see" the new foreign key, rather than just
setAccountManagerFK.

So here's my question:  Is there a way to "override" auto-update such
that I could force in a different foreign key or do I have to leave
auto-update disabled?  There are plenty of times where I would want to
handle auto-updates on a case by case basis, I think.

Am I just looking at this wrong?


On another topic, I posted the other day about not wanting to have a
validationQuery running all the time -- I did manage to get my app to
detect a PersistenceBrokerException (other than foreign key violations)
and set a counter such that the system would subsequently use a
validationQuery for the next n number of calls, and then ditch the
validationQuery again for speed.  That worked out great.




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Question about OJB references and manually setting foreign keys (Struts app)

Posted by Armin Waibel <ar...@apache.org>.
Hi Ian,

 > originally turned on auto-update as well, until I realized that if I
 > just wanted to link the Customer to a new Account Manager, I would
 > actually have to load the corresponding User record from persistence and
 > call "someCompany.setAccountManager (someUser)" or something to that
 > effect to get OJB to "see" the new foreign key, rather than just
 > setAccountManagerFK.

If you INSERT an object, it is possible only to link the FK values 
without the referenced objects available (since rc6). When OJB try to 
link the new object (set FK) but the referenced object was missed, the 
setting of FK values will be skipped.


 > So here's my question:  Is there a way to "override" auto-update such
 > that I could force in a different foreign key or do I have to leave
 > auto-update disabled?  There are plenty of times where I would want to
 > handle auto-updates on a case by case basis, I think.
 >
This feature (dynamically change of auto-xxx settings at runtime) will 
be introduced in version 1.1


 > On another topic, I posted the other day about not wanting to have a
 > validationQuery running all the time -- I did manage to get my app to
 > detect a PersistenceBrokerException (other than foreign key violations)
 > and set a counter such that the system would subsequently use a
 > validationQuery for the next n number of calls, and then ditch the
 > validationQuery again for speed.  That worked out great.

I'm interested in your solution. In OJB 1.1 we will introduce a 
pluggable ValidationStrategy interface which will allows the user to 
implement more sophisticated "validation queries".

regards,
Armin


Ian Hunter wrote:

> I'm pretty new to OJB, so be gentle. I'm working on a Struts app, using
> the PB API, and I have a "Customer" object with an "Account Manager"
> reference to a "User" object.  
> 
> For instance, something like:
> 
> public Class User {
> 	public int getId();
> 	public String getName();
> }
> 
> Public Class Company {
> 	public int getId();
> 	public String getName();
> 	public int getAccountManagerFK();
> 	public User getAccountManager();
> }
> 
> For sake of convenience, I have a reference-descriptor within the
> Company class-descriptor with auto-retrieve set to true.  I had
> originally turned on auto-update as well, until I realized that if I
> just wanted to link the Customer to a new Account Manager, I would
> actually have to load the corresponding User record from persistence and
> call "someCompany.setAccountManager (someUser)" or something to that
> effect to get OJB to "see" the new foreign key, rather than just
> setAccountManagerFK.
> 
> So here's my question:  Is there a way to "override" auto-update such
> that I could force in a different foreign key or do I have to leave
> auto-update disabled?  There are plenty of times where I would want to
> handle auto-updates on a case by case basis, I think.
> 
> Am I just looking at this wrong?
> 
> 
> On another topic, I posted the other day about not wanting to have a
> validationQuery running all the time -- I did manage to get my app to
> detect a PersistenceBrokerException (other than foreign key violations)
> and set a counter such that the system would subsequently use a
> validationQuery for the next n number of calls, and then ditch the
> validationQuery again for speed.  That worked out great.
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org