You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by "Clute, Andrew" <An...@osn.state.oh.us> on 2003/12/08 23:27:38 UTC

Problem with Inheritence: Get the wrong class back!

So, say I have a concrete class named 'foo', and another concrete class
named 'bar' that extends foo.

In one instance of my code I do a QueryByIdentity for a class of type 'foo'
with a certain PK. This loads it into the cache with that Identity.

Later on, I attempt to do a QueryByIdentity for the same PK, but this time
with the class 'bar' (and in this case, this is perfectly legal casting) --
however, when OJB sees this PK in the cache, it returns that object, and
before it returns it all the way up it sees that foo is not assignable to
bar and throws a warning, and returns null.

So, in essence, I have a race condition -- if I first look for it with the
class being 'bar' it works great from then on using either 'foo' or 'bar',
but if I use 'foo' first, it is in the cache as 'foo' and will never be
returned as 'bar'.

Thoughts?


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: Problem with Inheritence: Get the wrong class back!

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi andrew,

ojb requires a primary key to be _unique_ within a hierarchy defined in 
the repository.

jakob

Clute, Andrew wrote:

> So, say I have a concrete class named 'foo', and another concrete class
> named 'bar' that extends foo.
> 
> In one instance of my code I do a QueryByIdentity for a class of type 'foo'
> with a certain PK. This loads it into the cache with that Identity.
> 
> Later on, I attempt to do a QueryByIdentity for the same PK, but this time
> with the class 'bar' (and in this case, this is perfectly legal casting) --
> however, when OJB sees this PK in the cache, it returns that object, and
> before it returns it all the way up it sees that foo is not assignable to
> bar and throws a warning, and returns null.
> 
> So, in essence, I have a race condition -- if I first look for it with the
> class being 'bar' it works great from then on using either 'foo' or 'bar',
> but if I use 'foo' first, it is in the cache as 'foo' and will never be
> returned as 'bar'.
> 
> Thoughts?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org