Oracle 9i empty-string-to-null writeProperty hack

From: Mike Kienenberger (mkienen..laska.net)
Date: Mon Apr 12 2004 - 14:41:03 EDT

  • Next message: Andrus Adamchik: "[ANN] 1.1M5 is out"

    I've just added this to my DataObject superclass to detect problems with
    Oracle 9i empty strings.
    This is required to insure that optimistic locking will work since otherwise
    the database will contain a null for a field while cayenne will still have
    an empty string cached for the value. It's unclear to me whether this
    should also be handled directly in cayenne.

    In my case, I'm attempting to remove any empty string writing from my
    application, so detection and correction is what I'm aiming for.

    -Mike

        public void writeProperty(String key, Object value)
        {
            if ( (value instanceof String) && (0 == ((String)value).length()) )
            {
                RuntimeException e = new RuntimeException("Oracle 9i doesn't
    support empty strings, and it has been converted to null in order to store
    in the database.");
                log.error(e); // replace with whatever notification method you
    use.
                value = null;
            }
                
            super.writeProperty(key, value);
        }
        



    This archive was generated by hypermail 2.0.0 : Mon Apr 12 2004 - 14:39:16 EDT