> I'd like to know what's the best way (and how) to use sequences for
> the primary keys of my persistent classes.
>
> I'm facing some problems I can't seem to solve: I can't manage to
> store my objects, and I get an exception like:
>
> KeyConstraintViolatedException: SQL failure while insert object data
> for class com.inetpsa.ae6.concept.Sentence, PK of the given object is
> [ id=2], object was [myobject tostring], exception message is
> [ORA-01400: cannot insert NULL into ("USER"."TABLE"."COLUMN")
>
> There's nothing in that table yet. But there are some other objects
> inserted by some scripts in other tables (dunno if that matters).
>
> I've specified the sequence-manager like so:
>
> <sequence-manager
> className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
> <attribute attribute-name="autoNaming" attribute-value="true"/>
> <attribute attribute-name="globalSequenceStart" attribute-value="1000"/>
> </sequence-manager>
>
> (notice I tried using the globalSequenceStart, but it doesn't seem to
> change a thing)
>
> On my base class's id field, I did:
> @ojb.field column="ID" jdbc-type="BIGINT" primarykey="true"
> autoincrement="database" sequence-name="seq1"
>
> (whether I name my sequence or not doesn't matter either, and anyway
> I've set autoNaming to true)
>
> And xDoclet generated the following mapping snippet:
>
> <field-descriptor
> name="id" column="ID"
> jdbc-type="BIGINT" primarykey="true"
> autoincrement="true" sequence-name="seq1"
> access="readonly"
> >
>
> Other information: I'm using OJB 1.0.3 with Oracle9i.
> I'm probably doing something wrong somewhere, but unfortunately, I
> don't know what :-(
> Any help or hints are welcome! TIA.
The problem is that in the field descriptor you specified the field as
auto-incremented by the database (ie. outside of OJB's scope, eg.
using in Oracle by using a trigger on insert into the table) whereas
the sequence manager specifies that you want OJB to handle the pk
values. You have two choices now:
* Leave the pk generation to the database. In that case, use the
native sequence manager.
* Leave the pk generation to OJB. You have to specify
autoincrement="ojb" in the XDoclet tag of the field, and you can
either use the NextVal or the StoredProcedure sequence manager. See
http://db.apache.org/ojb/docu/guides/sequencemanager.html for details
on both of them.
regards,
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]