hi daniel,

Daniel Perry wrote:

I didnt try that - didnt know about that option.
However, i sort of fixed the problem by executing the following code after
any update/insertions which may screw up ordering.  I think perhaps this is
better that the refresh=true option, as the cache is only cleared when data
is changed, so the cache will get hit for repeated reads on onaltered data.

    PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();
    broker.clearCache();

this may be indeed more efficient than refreshing on each cache hit.



Now that it handles the ordering, there is one further problem:


When i retrieve all the jobs, and their associated grades, i only want to
acheive objects whoose "deleted" vaiable is set to false.  This is easy with
jobs (as the query "where deleted=0" works fine), but again, i cant specify
a query for the grade objects.
I've resorted to a real bodge - loading all the grades, then going through
the jobs one by one, and removing any grades where deleted=true.

As with the default ordering of grade objects within a job object, is there
a way of specifying a default restriction (ie grade.deleted=0)

this can only be done using a query-customizer.
see http://db.apache.org/ojb/tutorial3.html#Customizing%20collection%20queries


hth
jakob


Thanks for your help, Daniel.

----- Original Message ----- From: "Jakob Braeuchi" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Friday, October 17, 2003 1:08 PM
Subject: Re: 1:n relationship (sub element ordering)




hi daniel,

have you tried refresh=true in collection-descriptor ? this forces a
reload of the grades even if job is in the cache.

jakob

Daniel Perry wrote:


ok, still cant figure this out. If i add the gradename column to the

query


string like so:

String queryStr ="select job from " + Job.class.getName() + " where
deleted=0 order by jobname,gradename";

it thows an exception (understandibly) - it's trying to sort by

gradename in


the wrong query:


SELECT A0.deleted,A0.jobname,A0.id,jobname,gradename FROM job A0 WHERE A0.deleted = 0 ORDER BY 4,5

However, if i restart tomcat, the grade elements in jobs are sorted by

name


(due to collection descriptior in the repositry), the ordering is lost

when


i add a grade to a job - it appears at the end until the database is
restarted.

If there isnt a way to sort these elements, can i bodge it by clearing

the


cache (assuming thats why i get the wrong ordering after entering data)?
How do i do this?

Thanks,

Daniel.

----- Original Message ----- From: "Daniel Perry" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Thursday, October 16, 2003 6:27 PM
Subject: 1:n relationship (sub element ordering)





I've got two classes with a 1:n relationship - job and grade
I want to order by the results of an OQL query by the field "jobname"

from


the table job, then within each job by the field "gradename".

String queryStr= "select job from " + Job.class.getName() + " where
deleted=0 order by jobname";

The above handles the first bit of the ordering, but i am not sure how

to


do


the second level ordering.

Both the job and grade have fields titled "deleted", i only want to

select


objects that dont have the deleted fields set. The above query ignores

jobs



with deleted set to 1, but not grades. How can i acheive this?

Thanks for you help!

Daniel.


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




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



Reply via email to