Re: Primary key of type BINARY

[email protected] Mon, 14 Jun 2010 19:09:54 +1000
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Hello  Jorge,

Your approach sounds reasonable -- it is a Java bug that equals does not work for Arrays.

There is probably more to full support for binary fields though, for example toString of the arrays.

(Binary keys are a bit scary in general, I would normally stick to simple types.)

If you produce a set of patches plus a test case that works for MySQL and HSQL then that would be a valuable contribution.

Thanks,

Anthony

At 08:01 PM 10/06/2010, Jorge Cercas wrote:
>  
>
>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
>

Dr Anthony Berglas, [email protected]       Mobile: +61 4 4838 8874
Just because it is possible to push twigs along the ground with ones nose
does not necessarily mean that is the best way to collect firewood.


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
c75b05c.jpg (image/jpeg, 4.1 KB) - not displayed