Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-1259

Wrong Mapping for NUMERIC Type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.0.5
    • 1.2.5, 3.0 beta 1, 2.0.5
    • None
    • None

    Description

      Hello!
      We are using cayenne and found a bug in class:
      org.apache.cayenne.dba.TypesMapping

      follow lines:

          public static String getJavaBySqlType(int type, int length, int precision) {
              if (type == Types.NUMERIC && precision == 0) {
                  type = Types.INTEGER;
              }
              return (String) sqlEnumJava.get(new Integer(type));
          }
      

      problem occurs when we have NUMERIC(12, 0) which is more then Integer! (Integer has only 10 digets).
      And we wish to conver it to Long not to louse any digets.

      I can sugest to use sumething like this:

          public static String getJavaBySqlType(int type, int length, int precision) {
           if (type == Types.NUMERIC && precision == 0 && length < 10) {
      	    if(length < 10){
                  	type = Types.INTEGER;
      	    } else if (length < 20) {
      		type = Types.LONG;
      	    }
              }
              return (String) sqlEnumJava.get(new Integer(type));
          }
      

      Attachments

        1. CAY-1259.patch
          0.8 kB
          Evgeny Ryabitskiy

        Activity

          People

            antidote Andrey Razumovsky
            apparition Evgeny Ryabitskiy
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: