You should generally let the database set the OID for an object.  If you
load the object, the OID is set and therefore it will do an UPDATE when
storing.  If it's new, the OID is empty and therefore will do an INSERT.  If
you provide an OID for a new object (for example, get a value manually from
a sequence generator) then you still get the correct behavior.  It's only
when you do something "atypical" that you should need to use the
ObjectModification parameter.



-----Original Message-----
From: Ron Gallagher [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 04, 2003 4:53 PM
To: OJB Users List
Subject: Re: newbie question


Anthony --

There are two versions of the store method provided by the PersistenceBroker

store(Object)
store(Object,ObjectModification)

It appears that you're using the first version.  In this case, ojb will
first do a select against your db to see if the record exists.  If it does,
then ojb will do an update.  If it doesn't, then ojb will do an insert.

To force ojb to do an insert or an update, use the second version of the
store method and pass either
org.apache.ojb.broker.util.ObjectModificationDefaultImpl#INSERT or
org.apache.ojb.broker.util.ObjectModificationDefaultImpl#UPDATE.

Ron Gallagher
Atlanta, GA
[EMAIL PROTECTED]

> 
> From: "Anthony E. Carlos" <[EMAIL PROTECTED]>
> Date: 2003/08/04 Mon PM 04:47:19 EDT
> To: [EMAIL PROTECTED]
> Subject: newbie question
> 
> Hello all,
> 
> I'm using the PB API and can store a simple object to a table. Even
> though table has a primary key constraint on the id column, if I try to 
> store a different object with the same id, there is no primary key 
> constraint violation. In fact, OJB _UPDATES_ the existing matching row 
> in the database, instead of trying to INSERT a new row (which would 
> trigger the integrity constraint). I'm using Oracle 8i.
> 
> My question, therefore, is:
> 
> Do I have to perform my own referential integrity checks when I use
> OJB? Am I missing a basic idea behind OJB (like the lack of a need for 
> referential integrity)?
> 
> I've searched the mail archives and the online docs, but can't find 
> the
> answer to these simple questions.
> 
> Thanks,
> 
> Anthony Carlos
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


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


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

Reply via email to