Hi Stijn,

at the end of writing this mail I found that you are using "inheritance hierarchy to multiple joined tables" for Candidate. The ODMG-api doesn't work properly with this feature (PB-api does, sorry this was only noted in 1.0.1 release-notes). Additionally you define in Person class-descriptor Candidate as extent class. Mixing these features doesn't make sense (think so). So remove the the 'super' reference in Candidate and only use 'extent' the feature to tell OJB about the hierarchy.

Maybe the suggestions below are helpful too.

Armin

Stijn de Witt wrote:
Hi Armin, thanks for your response.
I think I have a bug in my code too... :)
I am using 1.0.0, should I upgrade?


You can give it a try, but if possible get latest from CVS (use the OJB_1_0_RELEASE branch, in trunk development for OJB1.1 take place). This include latest bug fixes (should be stable).



I'd be happy to send you the full project, it contains a bunch of persistence-capable classes and a single maven test case, of which I have posted the code.


If possible try to modify or add a test to the OJB test suite. If not possible please try to extract the problem and send me a test case with repository and all used classes for integration in OJB test suite.



Here are things I wonder about:

I am recreating the implementation and the database before the query, so I do this:
impl = OJB.newInstance()
db = impl.newDatabase();
db.open();
tx = impl.newTransaction();
tx.begin();
// INSERT CANDIDATE
tx.commit()
( I just think of this, I don't close the db.... mmm... probable cause? I'll check this next)
// RECREATE
impl = OJB.newInstance()
db = impl.newDatabase();
db.open()
tx = impl.newTransaction()
tx.begin
// DO QUERY
// LOG RESULTS
tx.commit()
// LOG RESULTS AGAIN


I never close the database (I think I read somewhere this is ok with ODMG? Or maybe not?)

Should be ok, Database#open(...) doesn't bind resources.
Maybe a problem could be the different Implementation instances. It's recommended to use a single instance for each used DB. You can encapsulate the Implementation and Database instance in a helper class and pass this class to your test methods or lookup the class in the test methods.



I just make sure I commit/rollback the transaction and then let all objects go out of scope.

It is this way because I made an openDatabase function which is called from submitCandidate() and queryCandidates()

Is this way of approaching it fine by itself? Should I use another approach?

About the int and Integer, I use int. I did not try Integer, should I?

I wonder that the PK field the created object is '0', normally the used SequenceManager starts with id '1'. If you use int for PK/FK fields it's not allowed to use 0, because this was used as 'null' representation for primitive fields.
See http://db.apache.org/ojb/docu/faq.html#primitiveNull


<snip>
testQueryCandidate: Found candidate [EMAIL PROTECTED]
salutation==null
title==null
initials==null
middleName==de
lastName==Witt
firstName==Stijn
birthDate==null
nationality==null
[EMAIL PROTECTED];
street==MyStreet;
houseNr==7;
zipCode==MYZIP BM;
city==MyCity;
state==;
country==NL;
type==homeAddress;
</snip>



regards, Armin

The funny thing is, the objects are inserted fine. If I remove the first section of the code that inserts the object, I get only null objects from the query. If I leave the insert code in, I get only the last object (The one I just inserted) back ok, the rest is null. I thought of caching, but ObjectCacheEmptyImpl made no difference.

Greetings,
-Stijn


Armin Waibel wrote:

Hi Stijn,

really strange. Checked your repository, seems ok. But there have to be a bug in your code (or improbable in OJB ;-)).Which version of OJB do you use? Did you try 1.0.1 or latest from CVS branch?
Seems that all found objects has id==0 - strange again. Do you use int or Integer type for PK/FK fields, did you try to use Integer?


regards,
Armin

Stijn de Witt wrote:

Anyone?


Stijn de Witt wrote:

Ok, I changed the cache settings in repository_database.xml to ObjectCacheEmptyImpl, like this:

<object-cache class="org.apache.ojb.broker.cache.ObjectCacheEmptyImpl"/>
<!--object-cache class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
<attribute attribute-name="timeout" attribute-value="900"/>
<attribute attribute-name="autoSync" attribute-value="true"/>
</object-cache-->


But it didn't help one bit....

-Stijn


Stijn de Witt wrote:

It's the strangest thing, if I remove the submit test and only do the query, NONE of the objects are ok...This smells like a caching problem to me...


Stijn de Witt wrote:

I am having a strange problem. I have a class Person, a class Candidate that extends Person and a class Address that has a many-to-one relationship with Person. I created a testcase that inserts a candidate with lastName=="Witt", with a homeAddress, and then does a query for all objects with that lastName. The first time everything seemed fine, but after repeated runs, although the object is inserted ok each time, and the query returns exactly the right number of objects, only the last object is materialized. The first objects have all fields set to NULL....? (The null fields in the last object are ok, I just never set them).

Could you look at the code and results below? I am sorry this has become a lengthy post.

Thanks in advance for any help,

-Stijn





--------------------------------------------------------------------- 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]




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



Reply via email to