Mike Jackson wrote:
I'm running on an Oracle database (8i) with insert triggers to create
artifical keys for my table records.  The howtos seemed to indicate that
SequenceManagerNativeImpl might be the proper sequence manager to use but
the keys are coming out goofy, so clearly I'm not understanding or
something.

Like Armin pointed out, you can use the "NextVal" SequenceManager with Oracle.

However, that setup is meant to be used with DB-sequences, not triggers.

If you have a table T with a simple integer PK field T_ID for which you want
autoincement in OJB, you can use a DB sequence (let's call it SEQ_T) and
the NextVal SequenceManager. In your OJB connection descriptor you would then
configure something like this:
 <jdbc-connection-descriptor jcd-alias="<your alias>" ...
   ...
   <sequence-manager 
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
    <attribute attribute-name="autoNaming" attribute-value="false"/>
   </sequence-manager>

In your OJB class descriptor you would map the autoincrement for T.PK to SEQ_T 
with:
 <class-descriptor class="<package.class>" table="T">
        <field-descriptor column="T_ID" name="id" ... primarykey="true" 
autoincrement="true" sequence-name="SEQ_T"


If you want to use a stored procedure for the insert operations, Ron Gallagher's method is the way to go.


If you end up somewhere "in between", eg you have a trigger assigning some values on insert and your only problem is that OJB won't "see" this change and Java objects in memory are out of synch with DB, the afterStore hook that Armin pointed to is a good place to put programmatic calls for refreshing objects in memory.

Or if you have a centralised point for storing your objects in a back-end you 
can
add your own after-store calls there.

Refreshing a field in memory after storage can look eg like this (using PB API):

 public static final String[] ATTRIBUTES = new String[]{"fieldName"};

 ...

 broker.removeFromCache(object);
 Criteria crit = ... construct a criteria for readback of object ...
 query = QueryFactory.newReportQuery(object.getClass(), ATTRIBUTES, crit, 
false);
 Iterator iter = broker.getReportQueryIteratorByQuery(query);
 if (iter.hasNext()) {
  Object[] columns = (Object[]) iter.next();
  ClassDescriptor cld = broker.getClassDescriptor(clazz);
  PersistentField ojbField = 
cld.getFieldDescriptorByName("fieldName").getPersistentField();
  ojbField.set(object, columns[0]);
  if (iterator instanceof OJBIterator) {
   ((OJBIterator) iterator).releaseDbResources();
  }
 }

Might not be the most beautiful programming pattern, but it's a starting point.

Regards,
 Martin

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



Reply via email to