Re: [JIRA] Commented: (CAY-811) Meaningful identity columns: user provided PK values are ignored

From: Tore Halset (halse..vv.ntnu.no)
Date: Thu Aug 02 2007 - 11:35:18 EDT

  • Next message: Andrus Adamchik: "Re: [JIRA] Commented: (CAY-811) Meaningful identity columns: user provided PK values are ignored"

    On Aug 2, 2007, at 14:59 , Andrus Adamchik wrote:

    > On Aug 2, 2007, at 3:52 PM, Tore Halset wrote:
    >
    >> On Aug 2, 2007, at 14:43 , Tore Halset wrote:
    >>
    >>> Handling null as 0 can probably lead to other problems as well.
    >>> Perhaps 'NullNumber extends Number' could be used? Or creating a
    >>> (empty) Null-interface and then subclass Integer, Long and so on?
    >>
    >> The last one would not work as Integer is final.
    >>
    >> - Tore.
    >
    > I didn't quite understand the proposed solution (aside from the
    > "final" thing). What are we going to use NullNunber for? Could
    > maybe post some code examples?

    A better name would be UnsetPrimitiveNumber extending Number and
    return 0 for all the methods. That way it would be the almost same as
    new Integer(0), but could be tested for its type.

    I have digged a bit down in the POJO code and it looks like this
    approach will not work. Using reflection on a POJO, java will report
    the same for an unset int as an int set to 0. So (at least from a
    reflection point of view) it is the same.

    Could we use the DbAttribute.isGenerated flag to determine if the new
    Integer(0)-value should be handled? Attached is a patch that explain
    this variant. It looks like this variant passes all the junit tests
    and also fixes my problem.

      - Tore.
    Index: framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/
    cayenne/access/DataDomainInsertBucket.java
    ===================================================================
    --- framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/
    cayenne/access/DataDomainInsertBucket.java (revision 562134)
    +++ framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/
    cayenne/access/DataDomainInsertBucket.java (working copy)
    ..-144,8 +144,12 @@
                                  .readPropertyDirectly(object);
                          if (value != null) {
    - // treat numeric zero values as nulls
    requiring generation
    - if (!(value instanceof Number && ((Number)
    value).intValue() == 0)) {
    + // POJO/JPA with generated key mapped as a
    primitive type will
    + // have a Number with value 0 for a unset value
    + if (!(supportsGeneratedKeys
    + && dbAttr.isGenerated()
    + && (value instanceof Number) &&
    ((Number) value)
    + .intValue() == 0)) {
                                  idMap.put(dbAttrName, value);
                                  continue;
                              }



    This archive was generated by hypermail 2.0.0 : Thu Aug 02 2007 - 11:36:12 EDT