Re: Bug in prepareForAcces..aseContext ?

From: Andreas Pardeike (a..sys.se)
Date: Tue Mar 18 2008 - 11:38:27 EDT

  • Next message: Razumovsky Andrey: "ROP & lifecycle"

    Nevermind. I had the second Object pointing to a view and in that
    view, I forgot that
    even if I set the column type to VARCHAR, the select behind the view
    was fetching from
    columns of type CHAR. That resulted in my primary key being filled
    with spaces.

    Interesting though, if I map an object to a table with CHAR columns
    (all our legacy
    tables have that!) I can still define the column type in the Cayenne
    modeller to be
    VARCHAR and that works! I had that too on the view but it didn't do
    the trick.

    Why is that so?

    /Andreas Pardeike

    On 18 mar 2008, at 14.55, Andreas Pardeike wrote:

    > Hi,
    >
    > maybe I am totally off here, but I just tried to find out why my to-
    > one relationship did not work and I went and traced the code for
    > 3.0M3. Seems something is wrong in prepareForAcces..aseContext:
    >
    > This is my version and to me this looks like 'objects[0]' is never
    > really used (see marker ? >>>>). As a result,
    > 'object.getPersistenceState()' will of course still be
    > PersistenceState.HOLLOW and the FaultFailureException is thrown.
    >
    > Regards,
    > Andreas Pardeike
    >
    >
    >
    > public void prepareForAccess(Persistent object, String property,
    > boolean lazyFaulting) {
    > if (object.getPersistenceState() == PersistenceState.HOLLOW) {
    >
    > ObjectId oid = object.getObjectId();
    > List<?> objects = performQuery(new ObjectIdQuery(oid,
    > false, ObjectIdQuery.CACHE));
    >
    > if (objects.size() == 0) {
    > throw new FaultFailureException(
    > "Error resolving fault, no matching row exists
    > in the database for ObjectId: "
    > + oid);
    > }
    > else if (objects.size() > 1) {
    > throw new FaultFailureException(
    > "Error resolving fault, more than one row
    > exists in the database for ObjectId: "
    > + oid);
    > }
    > ? >>>>
    > // sanity check...
    > if (object.getPersistenceState() !=
    > PersistenceState.COMMITTED) {
    >
    > String state =
    > PersistenceState.persistenceStateName(object
    > .getPersistenceState());
    >
    > // TODO: andrus 4/13/2006, modified and deleted states
    > are possible due to
    > // a race condition, should we handle them here?
    >
    > throw new FaultFailureException(
    > "Error resolving fault for ObjectId: "
    > + oid
    > + " and state ("
    > + state
    > + "). Possible cause - matching row is
    > missing from the database.");
    > }
    > }
    >
    > // resolve relationship fault
    > if (lazyFaulting && property != null) {
    > Property propertyDescriptor =
    > getEntityResolver().getClassDescriptor(
    >
    > object.getObjectId().getEntityName()).getProperty(property);
    >
    > // this should trigger fault resolving
    > propertyDescriptor.readProperty(object);
    > }
    > }



    This archive was generated by hypermail 2.0.0 : Tue Mar 18 2008 - 11:39:04 EDT