Re: Problems with MySql id type with AUTO_INCREMENT

From: Tobias SCHOESSLER (Tobias.Schoessle..nvienna.org)
Date: Tue Sep 26 2006 - 07:11:43 EDT

  • Next message: Kevin Menard: "Re: Why is method encodeProperty(String, Object, boolean) of XMLEncoder private?"

    Andrus,

    I am referring to http://issues.apache.org/cayenne/browse/CAY-639 and our
    discussion below.

    I am using cayenne 1.2.1 now. I mapped all AUTO_INCREMENTED primary keys of
    sql type unsigned int as BIG_INT in cayenne.

    Cayenne correctly returns DataObjects with a primary key of type Long when
    using SelectQuery, when creating new objects or using getToXXX navigation
    to retrieve the object .

    But when I use SQLTemplate to retrieve the same DataObject cayenne still
    returns a pk of type Integer ...

    These are my test cases:

                 public void testDocumentPkViaSelectQuery() {
                      List<TldDocument> docList = dataContext.performQuery(new
    SelectQuery(TldDocument.class, null));
                      assertEquals(Long.class,
    docList.get(0).getObjectId().getIdSnapshot().get(TldDocument.DOCUMENT_UID_PK_COLUMN).getClass());

                 }

                 public void testDocumentPkViaSQLTemplate() {

                      String sqlSelect = " select * ";
                      String sqlFrom = " from TLD_DOCUMENT doc ";

                      SQLTemplate query = new SQLTemplate(TldDocument.class,
    sqlSelect + " " + sqlFrom);
                      List<TldDocument> docList =
    dataContext.performQuery(query);

                      assertEquals(Long.class,
    docList.get(0).getObjectId().getIdSnapshot().get(TldDocument.DOCUMENT_UID_PK_COLUMN).getClass());

                 }

    testDocumentPkViaSelectQuery passes.

    testDocumentPkViaSQLTemplate fails.

    thanks, regards

    Tobias.

                                                                               
                 Andrus Adamchik
                 <andru..bjectsty
                 le.org> To
                                           cayenne-use..ncubator.apache.org
                 Tuesday, 29 cc
                 August 2006 15:35
                                                                       Subject
                                           Re: Problems with MySql id type
                 Please respond to with AUTO_INCREMENT
                 cayenne-use..ncu
                 bator.apache.org
                                                                               
                                                                               
                                                                               
                                                                               

    I'd appreciate that.

    Andrus

    On Aug 29, 2006, at 5:31 PM, Tobias SCHOESSLER wrote:

    > ok, I got it. You want me to add a Jira entry for this? I never did
    > this
    > before ... : |
    >
    >
    >
    >
    >
    >
    > Andrus Adamchik
    > <andru..bjectsty
    >
    > le.org> To
    > cayenne-
    > use..ncubator.apache.org
    > Tuesday,
    > 29 cc
    > August 2006 15:19
    >
    > Subject
    > Re: Problems with MySql id type
    > Please respond to with AUTO_INCREMENT
    > cayenne-use..ncu
    > bator.apache.org
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > On Aug 29, 2006, at 4:16 PM, Tobias SCHOESSLER wrote:
    >
    >> But still you are right there is a bug in mysql too. If the column
    >> type is
    >> INT and not INT UNSIGNED it should return java.lang.Integer but it
    >> returns
    >> java.lang.Long instead. This was my first observation.
    >
    > Still probably worth fixing the mapping to follow the docs.
    >
    >
    >> but why does cayenne need BIGINT mapping set for the column to
    >> retrieve it
    >> as a java.lang.Long? I understand that this is unrelated to the bug
    >> in the
    >> mysql jdbc driver mentioned above.
    >
    > This is simply a workaround for the bug. BIGINT has a default JDBC
    > mapping to java.lang.Long. So this consistently produced a Long
    > during select and when reading auto-incremented value via JDBC.
    >
    > Andrus
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Sep 26 2006 - 07:11:59 EDT