Primary key of type BINARY

Jorge Cercas <[email protected]> Thu, 10 Jun 2010 11:01:08 +0100
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Hello all,

I am currently evaluating SimpleORM and may have come across a possible
issue (using MySQL 5.1):
I have defined a table with primary key of type BINARY(16), and when I
invoke session.find(Customer.CUSTOMER, id), an exception is thrown that
goes something like:
    simpleorm.utils.SException$InternalError: Bad PKey class [B '[B@3eca90'
!equal() 'class [B' [B@16672d6

I have looked at the code in simpleorm.utils.SUte.trimStringEquals(firstObj,
secondObj). The line that says
"if (!(firstObj instanceof String))" is causing a .equals() type comparison
on the two objects of type Array.

I have added the following code to the method so that objects of type Array
go through a different test.
NOTE: I have not tested this code extensively neither have I tested it for
all cases - I have tested it
with a table column of type BINARY(16) and corresponding class field of type
SFieldBytes

*Original code:*

    if (!(firstObj instanceof String)) {
      return firstObj.equals(secondObj);
    }

*New code:*

    if (!(firstObj instanceof String)) {
      if(firstObj.getClass().isArray() && null != secondObj &&
secondObj.getClass().isArray()) {
        int len1 = Array.getLength(firstObj), len2 =
Array.getLength(secondObj);
        if(len1 != len2) {
          return false;
        }
        len1--;
        for(; len1 > -1; len1--) {
          Object o1 = Array.get(firstObj, len1), o2 = Array.get(secondObj,
len1);
          if(!o1.equals(o2)) {
            return false;
          }
        }
        return true;
      }
      return firstObj.equals(secondObj);
    }

Please give me your input regarding this issue.
Thanks