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 Robert Crawford <cr...@kloognome.com> on 2004/07/29 04:37:30 UTC

Negative Sequence Numbers?

I'm using database sequence numbers with MySQL, and keep getting negative
numbers for the primary keys. I understand these are coming from a
temporary sequence ID used by OJB, but I thought that setting the right
platform, sequence manager, and field attributes (primarykey="true"
autoincrement="true" access="readonly") would force OJB to use the
database sequence.

I'm sure I'm missing something very simple; anyone know where I should look?

Thanks!


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


Re: Negative Sequence Numbers?

Posted by Robert Crawford <cr...@kloognome.com>.
Armin Waibel said:
> Robert Crawford wrote:
>
>> Armin Waibel said:
>>
>>>Robert Crawford wrote:
>>>
>>>
>>>>Armin Waibel said:
>>>>
>>>>
>>>>>Do you only use the PB-api? This bug is odmg-api related.
>>>>
>>>>
>>>>I only use the PB-api.
>>>>
>>>
>>>Then you shouldn't get problems with negative sequence numbers.
>>>Can you describe me with some pseudo code an test case to reproduce your
>>>problem?
>>
>>
>
> Don't you use transaction demarcation or is this code snip from an
> managed environment with JTA transaction?

I haven't been using transactions; that's one of the things I want to try
tonight. I have other code where it works fine as-is, though.


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


Re: Negative Sequence Numbers?

Posted by Armin Waibel <ar...@apache.org>.
Robert Crawford wrote:

> Armin Waibel said:
> 
>>Robert Crawford wrote:
>>
>>
>>>Armin Waibel said:
>>>
>>>
>>>>Do you only use the PB-api? This bug is odmg-api related.
>>>
>>>
>>>I only use the PB-api.
>>>
>>
>>Then you shouldn't get problems with negative sequence numbers.
>>Can you describe me with some pseudo code an test case to reproduce your
>>problem?
> 
>

Don't you use transaction demarcation or is this code snip from an 
managed environment with JTA transaction?

Armin

>>>From memory, the code looks something like this:
> 
> PersistenceBroker broker =
> PersistenceBrokerFactory.createPersistenceBroker(pbKey);
> User user = new User();
> user.setEmailAddress(emailAddress);
> // more setters here, nothing that touches the primary key
> broker.store(user);
> 
> At this point the database has a negative number for the primary key and,
> from what I can recall from my debugging, the user object has zero in the
> primary key field.
> 
> Here's the start of the class descriptor:
> 
> <class-descriptor
>     class="com.kloognome.accesscontrol.ojb.UserInstance"
>     table="ac_users">
>     <field-descriptor name="userNbr" column="user_nbr" jdbc-type="INTEGER"
> primarykey="true" autoincrement="true" access="readonly"/>
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Negative Sequence Numbers?

Posted by Robert Crawford <cr...@kloognome.com>.
Armin Waibel said:
> Robert Crawford wrote:
>
>> Armin Waibel said:
>>
>>>Do you only use the PB-api? This bug is odmg-api related.
>>
>>
>> I only use the PB-api.
>>
>
> Then you shouldn't get problems with negative sequence numbers.
> Can you describe me with some pseudo code an test case to reproduce your
> problem?

>From memory, the code looks something like this:

PersistenceBroker broker =
PersistenceBrokerFactory.createPersistenceBroker(pbKey);
User user = new User();
user.setEmailAddress(emailAddress);
// more setters here, nothing that touches the primary key
broker.store(user);

At this point the database has a negative number for the primary key and,
from what I can recall from my debugging, the user object has zero in the
primary key field.

Here's the start of the class descriptor:

<class-descriptor
    class="com.kloognome.accesscontrol.ojb.UserInstance"
    table="ac_users">
    <field-descriptor name="userNbr" column="user_nbr" jdbc-type="INTEGER"
primarykey="true" autoincrement="true" access="readonly"/>



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


Re: Negative Sequence Numbers?

Posted by Armin Waibel <ar...@apache.org>.
Robert Crawford wrote:

> Armin Waibel said:
> 
>>Do you only use the PB-api? This bug is odmg-api related.
> 
> 
> I only use the PB-api.
>

Then you shouldn't get problems with negative sequence numbers.
Can you describe me with some pseudo code an test case to reproduce your 
problem?

regards,
Armin

> 
> 
> 
> ---------------------------------------------------------------------
> 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: Negative Sequence Numbers?

Posted by Robert Crawford <cr...@kloognome.com>.
Armin Waibel said:
> Do you only use the PB-api? This bug is odmg-api related.

I only use the PB-api.




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


Re: Negative Sequence Numbers?

Posted by Armin Waibel <ar...@apache.org>.
Robert Crawford wrote:

> Armin Waibel said:
> 
>>Hi Robert,
>>
>>there is bug in ODMG-api FK assignment when using
>>SequenceManagerNativeImpl (using DB Identity columns).
>>Test case is in CVS and we will try to fix this problem asap.
>>
>>workaround: use the PB-api to insert new object with 1:1 reference
> 
> 
> I'm not sure I understand, because I'm already using the PB-api. I'll try
> to give your sample code a try tonight, though.
>

Do you only use the PB-api? This bug is odmg-api related.

Armin


> 
> ---------------------------------------------------------------------
> 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: Negative Sequence Numbers?

Posted by Robert Crawford <cr...@kloognome.com>.
Armin Waibel said:
> Hi Robert,
>
> there is bug in ODMG-api FK assignment when using
> SequenceManagerNativeImpl (using DB Identity columns).
> Test case is in CVS and we will try to fix this problem asap.
>
> workaround: use the PB-api to insert new object with 1:1 reference

I'm not sure I understand, because I'm already using the PB-api. I'll try
to give your sample code a try tonight, though.


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


Re: Negative Sequence Numbers?

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

there is bug in ODMG-api FK assignment when using 
SequenceManagerNativeImpl (using DB Identity columns).
Test case is in CVS and we will try to fix this problem asap.

workaround: use the PB-api to insert new object with 1:1 reference

Transaction tx = odmg.newTransaction();
tx.begin();
....
// cast to proprietary extended Transaction class version
// and get current PB
PersistenceBroker pb = ((TransactionExt) tx).getBroker();
if(!pb.isInTransaction())pb.beginTransaction();
pb.store(referencedObject);
...
db.makePersistent(mainObject);
tx.commit();


regards,
Armin


Robert Crawford wrote:
> I'm using database sequence numbers with MySQL, and keep getting negative
> numbers for the primary keys. I understand these are coming from a
> temporary sequence ID used by OJB, but I thought that setting the right
> platform, sequence manager, and field attributes (primarykey="true"
> autoincrement="true" access="readonly") would force OJB to use the
> database sequence.
> 
> I'm sure I'm missing something very simple; anyone know where I should look?
> 
> Thanks!
> 
> 
> ---------------------------------------------------------------------
> 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