Optimistic locking on datetime fields [Was: Questions about Ordering, Optimistic Locking and QueryTable]

From: Mike Kienenberger (mkienen..mail.com)
Date: Mon May 19 2008 - 10:47:31 EDT

  • Next message: Mike Kienenberger: "Custom Ordering [Was: Questions about Ordering, Optimistic Locking and QueryTable]"

    It's probably better to use three separate emails.

    I've seen issues with using Timestamp columns in Oracle and optimistic locking.

    The problem was that the date stored in the database was rounded by
    the JDBC driver.
    The solution was to upgrade the JDBC driver when it was finally fixed.
      The workaround was to pre-round the values before assigning them to
    a field.

    There's something similar probably going on with your situation. The
    way to check is to verify that what was written out to the database
    matches what was in the application. I suppose it's also possible
    that the rounding is occurring when the data is read back in.

    But if Optimistic Locking is failing on a field, it comes down to the
    value in the application not being considered equal to the value read
    from the database.

    On 5/18/08, Adrian Wiesmann <awiesman..omap.org> wrote:
    > Hello list
    >
    > Instead of writing three separate mails I thought it would make sense to
    > pack these three questions together:
    >
    > Ordering
    > --------
    > I am having a list of DataObjects where one field represents a human
    > readable Id. Something like this:
    >
    > "1.1.1" (as example)
    >
    > When using the (offline) ordering mechanism of Cayenne to order a list of
    > DataObjects, things get ugly when I am introducing numbers above 10. Like
    > the following example:
    >
    > 1.1.1
    > 1.1.2
    > 1.10.1
    > 1.10.2
    > 1.2.1
    > 1.2.2
    >
    > I would like to have the 1.10.x numbers below the 1.2.x numbers. Which
    > means I would like to sort mathematically and not alphabetically.
    >
    > Is there any possibility to tell Cayenne to sort differently? Or would I
    > need to add a new (virtual) field to the DataObject with a clean sort
    > number and have Cayenne sort that field instead?
    >
    >
    > Optimistic Locking
    > ------------------
    > My DataObjects contain a datetime field and a string field which both are
    > used for optimistic locking. Basically the fields contain the datetime of
    > the last change plus the user Id of the user persisting the change.
    >
    > When using optimistic locking with Derby everything works as expected.
    > When using the same code and configuration with PostgreSQL (7 and 8) I
    > receive an optimistic locking failure although nothing has changed on the
    > database in the meantime.
    >
    > When I then remove the datetime field only from the optimistic locking
    > check things work as expected.
    >
    > Has anybody experienced the same? Is this a known problem or am I missing
    > something?
    >
    >
    > QueryTable
    > ----------
    > We were discussing that on this list before. I am looking for a way to
    > generate DataObjects without a reference to a table in the database.
    > Something like a virtual DataObject.
    >
    > My usage scenario is it to have a DataObject which can be bound to the UI
    > but which is only used to prepare data for a query and never should be
    > persisted to the database.
    >
    > I remember some discussion about introducing some kind of inheritance to
    > Cayenne which would support my usage scenario. I just wanted to check back
    > with you if something already happened there?
    >
    > Thanks for your help.
    >
    > Cheers,
    > Adrian
    >
    > P.S: Andrus: I remember you talking about being interested in learning
    > about experiences with Apache Wicket? The Wicket Framework is great and
    > using it with Cayenne works like a charm. Wicket is really a webframework
    > done right!
    >



    This archive was generated by hypermail 2.0.0 : Mon May 19 2008 - 10:48:08 EDT