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 Armin Waibel <ar...@apache.org> on 2004/09/20 16:53:39 UTC

Re: Howto get sequence value before

Hi,

Lázaro Miguel Fung wrote:
> Hi,
> 
> How I can get a sequence value using SequenceManagerNextValImpl before OJB
> insert a new object in the DB.
> 

You can generate an Identity object before insert, then the PK fields 
will be set in object and you can get them from the generated Identity, see
http://db.apache.org/ojb/docu/guides/sequencemanager.html#Force+computation+of+unique+values

Another possibility is to lookup a new sequence value using 
SequenceManager#getUniqueValue(FieldDescriptor field) via
broker.serviceSequenceManager()
and then *set* the PK values by your own in the new object (The PK 
fields can be obtained from the ClassDescriptor and this from 
broker.getClassDescriptorFor(object)).

In both cases I recommend to use broker.store(Object obj, 
ObjectModification mod) for best performance.

Or use one of OJB callback interfaces to extract the PK value before 
insert (PersistenceBrokerAware, PBLifeCycleListener more info see javadoc).

All suggestions are not possible when database IDENTITY columns will be 
used (but you don't ;-)), see
http://db.apache.org/ojb/docu/guides/sequencemanager.html#Identity+based+sequence+manager

regards,
Armin


> TIA.
> 
> LFung
> 
> 
> 
> ---------------------------------------------------------------------
> 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