Hi Armin,

here a short example.

create TABLE FOO ( TAB_ID INTEGER PRIMARY KEY )
and put an entry into the table with ID = 0 (from SQL not from OJB)


/*****/ repoistory.xml

<class-descriptor class="org.apache.ojb.test.Foo" table="FOO" >

<field-descriptor name="tabId" column="TAB_ID" jdbc-type="DECIMAL" nullable="false" primarykey="true" autoincrement="true" />

<class-descriptor/>

/****/
public class Foo {

public Integer tabId;

//Add getter and setter

}



/****/
some test code

(...)
Criteria c = new Criteria();
c.addEqualTo( "tabId", new Integer( 0 ) );
Query q = new QueryByCriteria( Foo.class, c );

Foo myFoo = (Foo) pb.getObjectByQuery( q );

pb.beginTransaction();
pb.store( myFoo );
pb.commitTransaction();
(...)


and now you have two entries in your database (Integer PK with value 0 was interpreded as null and a new clone has been inserted)


This is actually a minor issue, since it is not possible through OJB to add a DB entry with a PK = 0, in this case the error will never occur.
However if you are using data inserted by other applications it is possible to have entries with ID = 0 to work with.


sorry I didn't tested the code, I hope it works...

bye
Danilo


Hi Danilo,

Danilo Tommasina wrote:

Hi,

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)


if so, I agree sounds like a bug. Can you post a test case to reproduce the problem or describe what to do with pseudo code?


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 )


For OJB 1.1 a complete refactoring of the primitive data types handling is scheduled.
Here you can post your proposals for the upcoming 1.1 version


http://nagoya.apache.org/wiki/apachewiki.cgi?OJBProjectPages/OJBOnePointOne



The workaround is to never use IDs = 0 and this is actually what I am doing ;)


or don't use primitive data types for PK fields in your pc objects (or do both ;-)).

regards,
Armin


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]






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to