I reported the same issue some months ago...
The problem lies in the support for primitive data types, since a primitive type cannot be null, the value 0 is interpreted as null.
It seems that non primitive data types also react the same way (even if they shouldn't, so from my point of view it is a bug)
Fetching an object with ID = 0 works, however OJB will handle the 0 value as null and put the next sequence value into the fetched object on next store or when calling a PeristenceBroker.retrieveAllReferencies( Object obj )
The workaround is to never use IDs = 0 and this is actually what I am doing ;)
bye Danilo
Hi,
It looks like OJB cannot fetch correctly records which have a BigInt primary key with value 0; at least in the following conditions;
- I'm using RC5
- Have a table (here Locations) with a primary key Id with a auto-increment sequence
- I'm using Oracle 9.2
- The table has a 1-N collection using a proxy.
For instance, I have the following mapping:
<class-descriptor class="Locations" table="LOCATIONS">
<field-descriptor name="id" column="ID"
jdbc-type="BIGINT" primarykey="true"
autoincrement="true"
sequence-name="locations_id_seq"/>
<field-descriptor name="latitude" column="LATITUDE" jdbc-type="BIGINT"/>
<field-descriptor name="longitude" column="LONGITUDE" jdbc-type="BIGINT"/>
...
<collection-descriptor name="collElements"
element-class-ref="Elements" proxy="true">
<inverse-foreignkey field-ref="locationid"/>
</collection-descriptor>
</class-descriptor>
Now in the database, there is a location with Id=0.
When I use OJB to fetch this record (with a criteria on Id=0), the resulting instance is correct except for the Id field which has the next sequence value.
Tracing the code, what happens is when the query is executed:
- RsIterator.getObjectFromResultSet reteive the simple fields correctly
- As there is a collection, retrieveCollections is called
- The query to retrieve the collection is built: Query fkQuery =
getFKQuery(obj, cld, cds);
- This retrieves the PK fields values (getFKQuery1toN ) which
indirectly calls getValuesForObject
- When the value for the Id is retrieved (getAutoIncrementValue), it is considered as Null (BrokerHelper.isNull) and thus the sequence is called.
Can this be considered a bug?
Are there any workarounds?
Thanks,
-Alex
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]