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 Claudio Romano <cl...@lindos.ch> on 2003/09/17 10:31:00 UTC

Sequence Manager

Hello ALL,

i have a little question concerning OJB + MySQL + MySQLSequenceManager:

How can i get the last inserted primarykey of a table?

thank
Claudio Romano

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


Re: Sequence Manager question

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

Guido Beutler wrote:


>>
>> autoNaming 'true' means that OJB build a sequence name for each 
>> field-descriptor (parent class-descriptor) automatic, except the 
>> sequence name was specified in the field-descriptor
>> file:///E:/intellij/OJB_Experimental/db-ojb/target/doc/sequencemanager.html#sequenceName 
>>
>>
>> 'false' means OJB does not try to build a sequence name and if no 
>> sequence name was set in field-descriptor an exception was thrown.
>>
> If I use autoNaming=false and set a sequence name, for what OJB uses the 
> sequence name?
> Is it like a primary key and different tables are mapped to one sequence 
> if I use the same sequence name in different class descriptors?
> I'm just interested in what OJB is doing there.
> 

Yep and when using the same sequence name for different tables made 
these tables 'extent aware' (a PK is unique over several DB tables).

SequenceManagerHighLowImpl use sequence-name as PK in OJB_HL_SEQ table, 
SequenceManagerInMemoryImpl use it in memory. When using 
SequenceManagerNextValImpl the used DB use a system table to map 
sequence-name and latest generated key.

Except SequenceManagerMSSQLGuidImpl, SequenceManagerNativeImpl these 
implementations do not use the specified sequence-names or try to build 
such names.

regards,
Armin

> best regards,
> 
> Guido
> 
>> regards,
>> Armin
>>
>>> * in the repository descriptors, specify the database-generated pk 
>>> fields
>>> as autoincrement='true' and with the sequence-name if you have
>>> autoNaming='false' in the above step
>>>
>>> * in the db table schema don't specify the database-generated fields as
>>> identity (whatever the syntax in DB2 is for this) but as a normal non-pk
>>> field (except for NOT NULL which should be present). Also do not connect
>>> the sequences to the pk-fields in the database, this is done by the
>>> sequence manager.
>>>
>>> Tom
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Sequence Manager question

Posted by Guido Beutler <gu...@hrs.de>.
Hi Armin,

Armin Waibel wrote:

> Hi,
>
> Thomas Dudziak wrote:
>
>> On Tue, 6 Apr 2004, Guido Beutler wrote:
>>
>>
>>> Can I choose the sequence implementation per class?
>>> There are only a few tables which uses DB sequences. For all other 
>>> tables the NextValImpl is ok.
>>> The problem is that only a few tables use DB sequences.
>>
>>
>>
>> Nope, currently not, though for an application you should choose how the
>> pk values are generated, and stick to this method for all tables, 
>> anyway.
>>
>
> SequenceManager implementations can only set per database (per 
> jdbc-connection-descriptor). If you really need this you need a 
> special SM implementation for managing different SM.
> If you interested I will try to write an alpha version of such an 
> implementation.
>
For my current problem read-only works fine so I don't think that I need 
a special sequence manager.
Maybe that a sequence manager for mixed environments (DB sequences and 
OJB sequences) maybe useful in
future. Thanks for the offer to write one!!  ;-)
For me this is not needed right now.

>> So if you have a mixed scenario where some pk values shall be 
>> generated by
>> the database (sequences),
>> and other come from the application, then I
>> think you probably should use the NextValImpl like this (Armin, please
>> correct me if I got it wrong):
>>
>> * specify NextValImpl in your connection descriptor with
>> autoNaming='true' if you only need one sequence, or with
>> autoNaming='false' if you require multiple sequence
>>
>
> autoNaming 'true' means that OJB build a sequence name for each 
> field-descriptor (parent class-descriptor) automatic, except the 
> sequence name was specified in the field-descriptor
> file:///E:/intellij/OJB_Experimental/db-ojb/target/doc/sequencemanager.html#sequenceName 
>
>
> 'false' means OJB does not try to build a sequence name and if no 
> sequence name was set in field-descriptor an exception was thrown.
>
If I use autoNaming=false and set a sequence name, for what OJB uses the 
sequence name?
Is it like a primary key and different tables are mapped to one sequence 
if I use the same sequence name in different class descriptors?
I'm just interested in what OJB is doing there.

best regards,

Guido

> regards,
> Armin
>
>> * in the repository descriptors, specify the database-generated pk 
>> fields
>> as autoincrement='true' and with the sequence-name if you have
>> autoNaming='false' in the above step
>>
>> * in the db table schema don't specify the database-generated fields as
>> identity (whatever the syntax in DB2 is for this) but as a normal non-pk
>> field (except for NOT NULL which should be present). Also do not connect
>> the sequences to the pk-fields in the database, this is done by the
>> sequence manager.
>>
>> Tom
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>


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


Re: Sequence Manager question

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

Thomas Dudziak wrote:
> On Tue, 6 Apr 2004, Guido Beutler wrote:
> 
> 
>>Can I choose the sequence implementation per class?
>>There are only a few tables which uses DB sequences. For all other 
>>tables the NextValImpl is ok.
>>The problem is that only a few tables use DB sequences.
> 
> 
> Nope, currently not, though for an application you should choose how the
> pk values are generated, and stick to this method for all tables, anyway.
> 

SequenceManager implementations can only set per database (per 
jdbc-connection-descriptor). If you really need this you need a special 
SM implementation for managing different SM.
If you interested I will try to write an alpha version of such an 
implementation.

> So if you have a mixed scenario where some pk values shall be generated by
> the database (sequences),
> and other come from the application, then I
> think you probably should use the NextValImpl like this (Armin, please
> correct me if I got it wrong):
> 
> * specify NextValImpl in your connection descriptor with
> autoNaming='true' if you only need one sequence, or with
> autoNaming='false' if you require multiple sequence
> 

autoNaming 'true' means that OJB build a sequence name for each 
field-descriptor (parent class-descriptor) automatic, except the 
sequence name was specified in the field-descriptor
file:///E:/intellij/OJB_Experimental/db-ojb/target/doc/sequencemanager.html#sequenceName

'false' means OJB does not try to build a sequence name and if no 
sequence name was set in field-descriptor an exception was thrown.

regards,
Armin

> * in the repository descriptors, specify the database-generated pk fields
> as autoincrement='true' and with the sequence-name if you have
> autoNaming='false' in the above step
> 
> * in the db table schema don't specify the database-generated fields as
> identity (whatever the syntax in DB2 is for this) but as a normal non-pk
> field (except for NOT NULL which should be present). Also do not connect
> the sequences to the pk-fields in the database, this is done by the
> sequence manager.
> 
> Tom
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Sequence Manager question

Posted by Thomas Dudziak <to...@first.gmd.de>.
On Tue, 6 Apr 2004, Guido Beutler wrote:

> Can I choose the sequence implementation per class?
> There are only a few tables which uses DB sequences. For all other 
> tables the NextValImpl is ok.
> The problem is that only a few tables use DB sequences.

Nope, currently not, though for an application you should choose how the
pk values are generated, and stick to this method for all tables, anyway.

So if you have a mixed scenario where some pk values shall be generated by
the database (sequences), and other come from the application, then I
think you probably should use the NextValImpl like this (Armin, please
correct me if I got it wrong):

* specify NextValImpl in your connection descriptor with
autoNaming='true' if you only need one sequence, or with
autoNaming='false' if you require multiple sequence

* in the repository descriptors, specify the database-generated pk fields
as autoincrement='true' and with the sequence-name if you have
autoNaming='false' in the above step

* in the db table schema don't specify the database-generated fields as
identity (whatever the syntax in DB2 is for this) but as a normal non-pk
field (except for NOT NULL which should be present). Also do not connect
the sequences to the pk-fields in the database, this is done by the
sequence manager.

Tom


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


Re: Sequence Manager question

Posted by Guido Beutler <gu...@hrs.de>.
Hi Tom,

Thomas Dudziak wrote:

>On Tue, 6 Apr 2004, Guido Beutler wrote:
>
>  
>
>>Hi Armin,
>>
>>Armin Waibel wrote:
>>
>>    
>>
>>>Hi,
>>>
>>>Guido Beutler wrote:
>>>
>>>      
>>>
>>>>NextValImpl is ok for me. There is a database sequence at the pk 
>>>>column which caused my problem.
>>>>After setting the readonly attribute for the primary key column at 
>>>>the repository everything worked fine.
>>>>        
>>>>
>>>hmm, this shouldn't work. If you set readonly the PK field will be not 
>>>passed to the DB (and the PK will not be set). This only works for 
>>>identity columns.
>>>      
>>>
>>??
>>The database generates the pk value and permits that you can pass a pk 
>>value at a insert statement.
>>Every insert statement, which contains the pk columns, causes a SQL 
>>Exception.
>>This is the reason, why read-only works, I think.
>>    
>>
>
>If the database (as opposed to OJB) automatically creates the pk value
>upon insertion of a new row, then you should indeed use the NativeImpl as
>this is what it's designed for.
>
>  
>
Can I choose the sequence implementation per class?
There are only a few tables which uses DB sequences. For all other 
tables the NextValImpl is ok.
The problem is that only a few tables use DB sequences.

>You should be aware that db-generated pk-values do not work in OJB when
>you have an inheritance hierarchy that is mapped onto multiple tables,
>e.g. B extends A and A mapped to TABLE_A, B mapped to TABLE_B.
>In this case you should let OJB insert the pk values using your sequence
>and the NextValImpl. Otherwise you get problems for instance when trying
>to retrieve all objects of type A.
>  
>
Currently there are no derived classes for that table but I'll keep it 
in mind, thanks for the hint.

best regards,

Guido


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


Re: Sequence Manager question

Posted by Thomas Dudziak <to...@first.gmd.de>.
On Tue, 6 Apr 2004, Guido Beutler wrote:

> Hi Armin,
> 
> Armin Waibel wrote:
> 
> > Hi,
> >
> > Guido Beutler wrote:
> >
> >> NextValImpl is ok for me. There is a database sequence at the pk 
> >> column which caused my problem.
> >> After setting the readonly attribute for the primary key column at 
> >> the repository everything worked fine.
> >
> >
> > hmm, this shouldn't work. If you set readonly the PK field will be not 
> > passed to the DB (and the PK will not be set). This only works for 
> > identity columns.
> 
> ??
> The database generates the pk value and permits that you can pass a pk 
> value at a insert statement.
> Every insert statement, which contains the pk columns, causes a SQL 
> Exception.
> This is the reason, why read-only works, I think.

If the database (as opposed to OJB) automatically creates the pk value
upon insertion of a new row, then you should indeed use the NativeImpl as
this is what it's designed for.

You should be aware that db-generated pk-values do not work in OJB when
you have an inheritance hierarchy that is mapped onto multiple tables,
e.g. B extends A and A mapped to TABLE_A, B mapped to TABLE_B.
In this case you should let OJB insert the pk values using your sequence
and the NextValImpl. Otherwise you get problems for instance when trying
to retrieve all objects of type A.
 
Tom



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


Re: Sequence Manager question

Posted by Guido Beutler <gu...@hrs.de>.
Hi Armin,

Armin Waibel wrote:

> Hi,
>
> Guido Beutler wrote:
>
>> NextValImpl is ok for me. There is a database sequence at the pk 
>> column which caused my problem.
>> After setting the readonly attribute for the primary key column at 
>> the repository everything worked fine.
>
>
> hmm, this shouldn't work. If you set readonly the PK field will be not 
> passed to the DB (and the PK will not be set). This only works for 
> identity columns.

??
The database generates the pk value and permits that you can pass a pk 
value at a insert statement.
Every insert statement, which contains the pk columns, causes a SQL 
Exception.
This is the reason, why read-only works, I think.

>
>> I had a db lock problem with db2 in former times when using 
>> NextValImpl but I think that is another problem.
>>
>
> I never used DB2, so sorry I can't help.
>
>> I havn't find a way to get the sequence name from db2 yet. So setting 
>> the name would currently not work.
>> Without beeing able to access the db sequence the readonly attribute 
>> is the only choice.
>
>
> Why you need the sequence name from your database? If you set 
> auto-naming=true in the sequence-manager descriptor, OJB will handle 
> all sequence names for you.
> http://db.apache.org/ojb/sequencemanager.html#noAutoBuild
>
> If you want to use your own sequence names, you can declare them on 
> field-descriptor level using the 'sequence-name' attribute.
>
Maybe that I have another problem. I thought that OJB recognizes that a 
sequence (at database !) is defined
for the column and would not generate inserts with pk columns in it. 
This seems not to be the case.
Without read-only set at repository, OJB passes a pk with correct value 
but the statement failed because of the
database sequence.

best regards,

Guido

> regards,
> Armin
>
>> Thanks for the hint!!
>>
>> best regards,
>>
>> Guido
>>
>>> regards,
>>> Armin
>>>
>>> Thomas Dudziak wrote:
>>>
>>>> On Mon, 5 Apr 2004, Guido Beutler wrote:
>>>>
>>>>
>>>>> Hi Tom,
>>>>>
>>>>> Readonly was a usefull hint. I removed the sequence name at the 
>>>>> class descriptor and added a
>>>>> readonly attribute. I still use nextVal sequence manager. This now 
>>>>> works for me.
>>>>> Thanks !!
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> I'm not sure that the sequence manager is used at all now. Please 
>>>> try the
>>>> SequenceManagerNativeImpl to see whether it works too as it seems 
>>>> to me
>>>> to be the more appropriate one in your case.
>>>>
>>>> Tom
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>


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


Re: Sequence Manager question

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

Guido Beutler wrote:

> NextValImpl is ok for me. There is a database sequence at the pk column 
> which caused my problem.
> After setting the readonly attribute for the primary key column at the 
> repository everything worked fine.

hmm, this shouldn't work. If you set readonly the PK field will be not 
passed to the DB (and the PK will not be set). This only works for 
identity columns.

> I had a db lock problem with db2 in former times when using NextValImpl 
> but I think that is another problem.
>

I never used DB2, so sorry I can't help.

> I havn't find a way to get the sequence name from db2 yet. So setting 
> the name would currently not work.
> Without beeing able to access the db sequence the readonly attribute is 
> the only choice.

Why you need the sequence name from your database? If you set 
auto-naming=true in the sequence-manager descriptor, OJB will handle all 
sequence names for you.
http://db.apache.org/ojb/sequencemanager.html#noAutoBuild

If you want to use your own sequence names, you can declare them on 
field-descriptor level using the 'sequence-name' attribute.

regards,
Armin

> Thanks for the hint!!
> 
> best regards,
> 
> Guido
> 
>> regards,
>> Armin
>>
>> Thomas Dudziak wrote:
>>
>>> On Mon, 5 Apr 2004, Guido Beutler wrote:
>>>
>>>
>>>> Hi Tom,
>>>>
>>>> Readonly was a usefull hint. I removed the sequence name at the 
>>>> class descriptor and added a
>>>> readonly attribute. I still use nextVal sequence manager. This now 
>>>> works for me.
>>>> Thanks !!
>>>
>>>
>>>
>>>
>>> I'm not sure that the sequence manager is used at all now. Please try 
>>> the
>>> SequenceManagerNativeImpl to see whether it works too as it seems to me
>>> to be the more appropriate one in your case.
>>>
>>> Tom
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Sequence Manager question

Posted by Guido Beutler <gu...@hrs.de>.
Hi Armin,

Armin Waibel wrote:

> Hi,
>
> AFAIK DB2 supports both kinds of DB side key generation:
> - use of identity columns via SequenceManagerNativeImpl
> - use of database based key generation via SequenceManagerNextValImpl
>
> I strongly recommend to use database based sequence generation in this 
> case, because identity based key generation is not "extent aware", 
> more info see sequence manager doc 
> http://db.apache.org/ojb/sequencemanager.html#SequenceManager%20implementations 
>
>
> Guido, I don't know which SM you like to use, but the 'sequence-name' 
> attribute has no effect when using SequenceManagerNativeImpl.
>
NextValImpl is ok for me. There is a database sequence at the pk column 
which caused my problem.
After setting the readonly attribute for the primary key column at the 
repository everything worked fine.
I had a db lock problem with db2 in former times when using NextValImpl 
but I think that is another problem.

I havn't find a way to get the sequence name from db2 yet. So setting 
the name would currently not work.
Without beeing able to access the db sequence the readonly attribute is 
the only choice.
Thanks for the hint!!

best regards,

Guido

> regards,
> Armin
>
> Thomas Dudziak wrote:
>
>> On Mon, 5 Apr 2004, Guido Beutler wrote:
>>
>>
>>> Hi Tom,
>>>
>>> Readonly was a usefull hint. I removed the sequence name at the 
>>> class descriptor and added a
>>> readonly attribute. I still use nextVal sequence manager. This now 
>>> works for me.
>>> Thanks !!
>>
>>
>>
>> I'm not sure that the sequence manager is used at all now. Please try 
>> the
>> SequenceManagerNativeImpl to see whether it works too as it seems to me
>> to be the more appropriate one in your case.
>>
>> Tom
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>


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


Re: Sequence Manager question

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

AFAIK DB2 supports both kinds of DB side key generation:
- use of identity columns via SequenceManagerNativeImpl
- use of database based key generation via SequenceManagerNextValImpl

I strongly recommend to use database based sequence generation in this 
case, because identity based key generation is not "extent aware", more 
info see sequence manager doc 
http://db.apache.org/ojb/sequencemanager.html#SequenceManager%20implementations

Guido, I don't know which SM you like to use, but the 'sequence-name' 
attribute has no effect when using SequenceManagerNativeImpl.

regards,
Armin

Thomas Dudziak wrote:
> On Mon, 5 Apr 2004, Guido Beutler wrote:
> 
> 
>>Hi Tom,
>>
>>Readonly was a usefull hint. I removed the sequence name at the class 
>>descriptor and added a
>>readonly attribute. I still use nextVal sequence manager. This now works 
>>for me.
>>Thanks !!
> 
> 
> I'm not sure that the sequence manager is used at all now. Please try the
> SequenceManagerNativeImpl to see whether it works too as it seems to me
> to be the more appropriate one in your case.
> 
> Tom
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Sequence Manager question

Posted by Thomas Dudziak <to...@first.gmd.de>.
On Mon, 5 Apr 2004, Guido Beutler wrote:

> Hi Tom,
> 
> Readonly was a usefull hint. I removed the sequence name at the class 
> descriptor and added a
> readonly attribute. I still use nextVal sequence manager. This now works 
> for me.
> Thanks !!

I'm not sure that the sequence manager is used at all now. Please try the
SequenceManagerNativeImpl to see whether it works too as it seems to me
to be the more appropriate one in your case.

Tom


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


Re: Sequence Manager question

Posted by Guido Beutler <gu...@hrs.de>.
Hi Tom,

Thomas Dudziak wrote:

>On Mon, 5 Apr 2004, Guido Beutler wrote:
>
>  
>
>>Hi,
>>
>>I use OJB RC6 and DB2. I want to insert a abject into a table with a 
>>sequence.
>>I  took the settings from documentation and added to database.xml :
>>
>>   <sequence-manager 
>>className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
>>     <attribute attribute-name="autoNaming" attribute-value="true"/>
>>  </sequence-manager>
>>
>>and at the class descriptor :
>>
>>      primarykey="true"
>>      autoincrement="true"
>>      sequence-name="TEST_SEQUENCE"
>>
>>OJB still tries to insert the pk field to which causes a SQL exception. 
>>DB2 expects that the field is not used
>>at the insert statement. DB2 then generates the pk value itself.
>>I also tried to leave the sequence name open but this had no effect.
>>What am I doing wrong?
>>    
>>
>
>How is the field defined in the database ?
>
>I'm no expert on sequence managers, but as far as I understand them, the
>difference between SequenceManagerNextValImpl and
>SequenceManagerNativeImpl is that for the former, in the database the
>field is defined as a normal field (no autoincrement/identity
>setting) whereas for the native impl the database increments the field
>automatically (without OJB intervening, thus you should have
>access='readonly' in this case).
>
>Tom
>  
>
Readonly was a usefull hint. I removed the sequence name at the class 
descriptor and added a
readonly attribute. I still use nextVal sequence manager. This now works 
for me.
Thanks !!

best regards,

Guido



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


Re: Sequence Manager question

Posted by Thomas Dudziak <to...@first.gmd.de>.
On Mon, 5 Apr 2004, Guido Beutler wrote:

> Hi,
> 
> I use OJB RC6 and DB2. I want to insert a abject into a table with a 
> sequence.
> I  took the settings from documentation and added to database.xml :
> 
>    <sequence-manager 
> className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
>      <attribute attribute-name="autoNaming" attribute-value="true"/>
>   </sequence-manager>
> 
> and at the class descriptor :
> 
>       primarykey="true"
>       autoincrement="true"
>       sequence-name="TEST_SEQUENCE"
> 
> OJB still tries to insert the pk field to which causes a SQL exception. 
> DB2 expects that the field is not used
> at the insert statement. DB2 then generates the pk value itself.
> I also tried to leave the sequence name open but this had no effect.
> What am I doing wrong?

How is the field defined in the database ?

I'm no expert on sequence managers, but as far as I understand them, the
difference between SequenceManagerNextValImpl and
SequenceManagerNativeImpl is that for the former, in the database the
field is defined as a normal field (no autoincrement/identity
setting) whereas for the native impl the database increments the field
automatically (without OJB intervening, thus you should have
access='readonly' in this case).

Tom


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


Sequence Manager question

Posted by Guido Beutler <gu...@hrs.de>.
Hi,

I use OJB RC6 and DB2. I want to insert a abject into a table with a 
sequence.
I  took the settings from documentation and added to database.xml :

   <sequence-manager 
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
     <attribute attribute-name="autoNaming" attribute-value="true"/>
  </sequence-manager>

and at the class descriptor :

      primarykey="true"
      autoincrement="true"
      sequence-name="TEST_SEQUENCE"

OJB still tries to insert the pk field to which causes a SQL exception. 
DB2 expects that the field is not used
at the insert statement. DB2 then generates the pk value itself.
I also tried to leave the sequence name open but this had no effect.
What am I doing wrong?

best regards,

Guido

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