RE: odmg/caching problem?

2003-10-14 Thread sclark
Here's what's happening: The certificate objects do indeed point back to the 
customer, but without customer.addCertificate(), the customer doesn't know about 
the certificates.

When you commit the transaction, the FK is copied into the certificates and 
everything is written to the database as expected.  At this point, the OJB cache 
contains the customer (with no certificates) and the certificates (each pointing 
to the customer).

When you do the query, a SELECT is run against the db (this always happens).  It 
finds that, e.g., customer ID 10 matches.  OJB then goes to materialize this 
customer object.  The first thing it does is to check the cache, where it finds 
the customer object from the previous transaction, which has no certificates.  
Because the object was found in the cache, we are done.  If the 'refresh' 
attribute on the 'certificates' collection-descriptor were set, then this 
collection would be refetched at this point and you'd see the certificates.

Now, let's suppose customer ID 10 was added in a prior run and we've just now 
added customer ID 11 in the current run.  Now our query finds two matching 
customers, 10 and 11.  10 is not in the cache yet, because we haven't touched it 
in this run.  So when OJB goes to materialize it, it ends up fetching the whole 
object from the db.  In contrast, 11 is already in the cache and has no 
certificates.  This is why "old" customers are displayed correctly while "new" 
ones are not.

Hope this helps,
-steve

Steve Clark
Technology Applications Team
Natural Resources Research Center/USGS
[EMAIL PROTECTED]
(970)226-9291

>To: [EMAIL PROTECTED]
>From: Gunnar Hilling <[EMAIL PROTECTED]>
>Subject: RE: odmg/caching problem?
>Date: Fri, 10 Oct 2003 02:47:05 +0200
>
>OK, now I hope I know ho to do this. I assume the behaviour is related to
>Caching? Because in some other Thread I think Thomas Mahler said, every
>Query would be executed on the Database. So I thought the results should
>be the same, no matter if written some Minutes before or immediately after
>tx.commit().
>
>Perhaps You could help me understand this behaviour?
>
>Thanks a lot,
>
>-Gunnar



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



RE: odmg/caching problem?

2003-10-10 Thread Gunnar Hilling
On Fri, 10 Oct 2003 14:50:44 +1300, Shane Mingins wrote:

>> -Original Message-
>> From: Gunnar Hilling [mailto:[EMAIL PROTECTED]
>> > Shane said:
>> > By using the auto-insert/update settings and the PersistenceBroker I get
>> > what I expect.
>> So far this is also working with odmg in my test (in the given code
>> example I'm persisting the Certificate-Object implicit:
>> 
>> customer.addCertificate(certificate);
>> 
>> without persisting certificate using db.makePersistant
> 
> Has that customer already been persisted or was that the first time?
the first time...
I'll try the other case soon
> 
> Shane



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



Re: odmg/caching problem?

2003-10-09 Thread Philippe Hacquin
You are right, OJB supports ODMG's "persistence by reachability": you 
just have to add new or already persisted objects to the DList of your 
root object, and its persistence will be handled transparently.

Anyway, you should theoretically place your read query in a transaction 
context to check your results:

tx.begin();// <--
   DList allProducts = (DList) query.execute();
Iterator iter = allProducts.iterator();
while (iter.hasNext())
{
customer=(Customer)iter.next();
System.out.println(customer.getBenutzername() + ": " +
customer.getCertificates().size());
}
tx.commit();// <--
I always place all read or write accesses in a transaction context, and 
everything goes fine.

I guess results should be right if the write and the read accesses would 
be in the same transaction context, too.

HTH

Gunnar Hilling wrote:

On Fri, 10 Oct 2003 14:03:05 +1300, Shane Mingins wrote:

 

By using the auto-insert/update settings and the PersistenceBroker I get
what I expect.
   

So far this is also working with odmg in my test (in the given code
example I'm persisting the Certificate-Object implicit:
customer.addCertificate(certificate);

without persisting certificate using db.makePersistant

 

Anyway as I have mentioned my experience is not vast so I would defer to
expert advice/opinion :-)
   



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


RE: odmg/caching problem?

2003-10-09 Thread Shane Mingins
> -Original Message-
> From: Gunnar Hilling [mailto:[EMAIL PROTECTED]
> > Shane said:
> > By using the auto-insert/update settings and the PersistenceBroker I get
> > what I expect.
> So far this is also working with odmg in my test (in the given code
> example I'm persisting the Certificate-Object implicit:
> 
> customer.addCertificate(certificate);
> 
> without persisting certificate using db.makePersistant

Has that customer already been persisted or was that the first time?

Shane

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



RE: odmg/caching problem?

2003-10-09 Thread Gunnar Hilling
On Fri, 10 Oct 2003 14:03:05 +1300, Shane Mingins wrote:


> 
> By using the auto-insert/update settings and the PersistenceBroker I get
> what I expect.
So far this is also working with odmg in my test (in the given code
example I'm persisting the Certificate-Object implicit:

customer.addCertificate(certificate);

without persisting certificate using db.makePersistant

> 
> Anyway as I have mentioned my experience is not vast so I would defer to
> expert advice/opinion :-)
> 
>


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



RE: odmg/caching problem?

2003-10-09 Thread Shane Mingins
I am not really qualified to explain ... others may take up that task ...
hello others??

I have actually decided (at this stage) to use the PersistenceBroker API
instead of the ODMG implementation.  It just seems to do what I want with
far less code.  Especially with 1:n:n relationships.

That said I think the way to view the ODMG API is that 1. You need to
manage your objects and 2. You need to manage your persistence.  And the two
are not the same thing.

For example ---

I create a Parent object, add some Children and then persist.  It works.
But if I retrieve the Parent object and add some Children and persist the
Parent ... the db is not updated with the new Children I need to persist
the Children as well.  My expectation would have been that it was taken care
of for me via my mappings.

By using the auto-insert/update settings and the PersistenceBroker I get
what I expect.

Anyway as I have mentioned my experience is not vast so I would defer to
expert advice/opinion :-)


Shane


> -Original Message-
> From: Gunnar Hilling [mailto:[EMAIL PROTECTED]
> Sent: Friday, 10 October 2003 1:47 p.m.
> To: [EMAIL PROTECTED]
> Subject: RE: odmg/caching problem?
> 
> On Fri, 10 Oct 2003 13:29:10 +1300, Shane Mingins wrote:
> 
> > Have u added the certificate to the customer?  Could not see that from
> code
> > posted.
> >
> No, I want to model a 1:n relation that is navigatable in both directions.
> so the foreign key is inserted in the Constructor of Certificate:
> 
> new Certificate(..., "customer");
> 
> This works fine for the creation of the foreign key field in the reference
> of Certificate
> 
> But You're right, changing the code to
> 
> customer.addCertificate(new Certificate(..., "customer"));
> 
> works...
> 
> I dropped this approach because I thought the Certificate Object would be
> added twice this way ... (It is, somehow, because the foreign key already
> exists).
> OK, now I hope I know ho to do this. I assume the behaviour is related to
> Caching? Because in some other Thread I think Thomas Mahler said, every
> Query would be executed on the Database. So I thought the results should
> be the same, no matter if written some Minutes before or immediately after
> tx.commit().
> 
> Perhaps You could help me understand this behaviour?
> 
> Thanks a lot,
> 
> -Gunnar
> 
> 
> 
> -
> 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]



RE: odmg/caching problem?

2003-10-09 Thread Gunnar Hilling
On Fri, 10 Oct 2003 13:29:10 +1300, Shane Mingins wrote:

> Have u added the certificate to the customer?  Could not see that from code
> posted.
> 
No, I want to model a 1:n relation that is navigatable in both directions.
so the foreign key is inserted in the Constructor of Certificate:

new Certificate(..., "customer");

This works fine for the creation of the foreign key field in the reference
of Certificate

But You're right, changing the code to

customer.addCertificate(new Certificate(..., "customer"));

works...

I dropped this approach because I thought the Certificate Object would be
added twice this way ... (It is, somehow, because the foreign key already
exists).
OK, now I hope I know ho to do this. I assume the behaviour is related to
Caching? Because in some other Thread I think Thomas Mahler said, every
Query would be executed on the Database. So I thought the results should
be the same, no matter if written some Minutes before or immediately after
tx.commit().

Perhaps You could help me understand this behaviour?

Thanks a lot,

-Gunnar



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



RE: odmg/caching problem?

2003-10-09 Thread Shane Mingins
Have u added the certificate to the customer?  Could not see that from code
posted.

Shane

> -Original Message-
> From: Gunnar Hilling [mailto:[EMAIL PROTECTED]
> Sent: Friday, 10 October 2003 1:28 p.m.
> To: [EMAIL PROTECTED]
> Subject: Re: odmg/caching problem?
> 
> Additional Detail:
> 
> Bothe the customer and the certificate are available when being created,
> only the relation (Collection) of the newly created customer is not
> updated when querying ...
> 
> > Hello,
> >
> > I got the following small program (snippet):
> >
> > Customer customer=new Customer("no", "one", "here", "0", "", 2,
> null);
> > tx = odmg.newTransaction();
> > tx.begin();
> > db.makePersistent(new Certificate("Z1\n", customer));
> > db.makePersistent(customer);
> > tx.commit();
> >
> > DList allProducts = (DList) query.execute();
> > Iterator iter = allProducts.iterator();
> > while (iter.hasNext())
> > {
> > customer=(Customer)iter.next();
> > System.out.println(customer.getBenutzername() + ": " +
> > customer.getCertificates().size());
> > }
> >
> > I think the Details don't matter: One Customer can have many
> Certificates
> > (1:n relationsship, navigatable in both directions here).
> >
> > Now the Problem:
> >
> > The Certificate created for the Customer is NOT listed in the first run
> of
> > the program, output:
> >
> > 1065740029439: 0
> > done!
> >
> > When running the program for a second time, the records created in the
> > first run are read correctly, output this time:
> >
> > 1065740029439: 1
> > 1065740078144: 0
> > done!
> >
> > ... and so on.
> > Anyone any clues?
> >
> > Thanks a lot,
> >
> > -Gunnar
> 
> 
> 
> -
> 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]



Re: odmg/caching problem?

2003-10-09 Thread Gunnar Hilling
Additional Detail:

Bothe the customer and the certificate are available when being created,
only the relation (Collection) of the newly created customer is not
updated when querying ...

> Hello,
>  
> I got the following small program (snippet):
> 
>   Customer customer=new Customer("no", "one", "here", "0", "", 2, null);
>   tx = odmg.newTransaction();
>   tx.begin();
>   db.makePersistent(new Certificate("Z1\n", customer));
>   db.makePersistent(customer);
>   tx.commit();
> 
>   DList allProducts = (DList) query.execute();
>   Iterator iter = allProducts.iterator();
>   while (iter.hasNext())
>   {
>   customer=(Customer)iter.next();
>   System.out.println(customer.getBenutzername() + ": " +
>   customer.getCertificates().size());
>   }
> 
> I think the Details don't matter: One Customer can have many Certificates
> (1:n relationsship, navigatable in both directions here).
> 
> Now the Problem:
> 
> The Certificate created for the Customer is NOT listed in the first run of
> the program, output:
> 
> 1065740029439: 0
> done!
> 
> When running the program for a second time, the records created in the
> first run are read correctly, output this time:
> 
> 1065740029439: 1
> 1065740078144: 0
> done!
> 
> ... and so on.
> Anyone any clues?
> 
> Thanks a lot,
> 
> -Gunnar



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



odmg/caching problem?

2003-10-09 Thread Gunnar Hilling
Hello,
 
I got the following small program (snippet):

Customer customer=new Customer("no", "one", "here", "0", "", 2, null);
tx = odmg.newTransaction();
tx.begin();
db.makePersistent(new Certificate("Z1\n", customer));
db.makePersistent(customer);
tx.commit();

DList allProducts = (DList) query.execute();
Iterator iter = allProducts.iterator();
while (iter.hasNext())
{
customer=(Customer)iter.next();
System.out.println(customer.getBenutzername() + ": " +
customer.getCertificates().size());
}

I think the Details don't matter: One Customer can have many Certificates
(1:n relationsship, navigatable in both directions here).

Now the Problem:

The Certificate created for the Customer is NOT listed in the first run of
the program, output:

1065740029439: 0
done!

When running the program for a second time, the records created in the
first run are read correctly, output this time:

1065740029439: 1
1065740078144: 0
done!

... and so on.
Anyone any clues?

Thanks a lot,

-Gunnar



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