persistence@glassfish.java.net

RE: byte [] primary keys...

From: Adam Leftik <adam.leftik_at_oracle.com>
Date: Mon, 18 Dec 2006 15:54:51 -0800

This is the one I have handy, per oracle support, it is packaged as Jdev project file --yuck. Let me know if you need more and/or would prefer junit test cases or some other form. In a nutshell, anytime you have relationships with byte [] pks you should see infinite loops. On merging you *could* see ClassCastExceptions. You will never get a cache hit when you should.

-----Original Message-----
From: Tom Ware [mailto:tom.ware_at_oracle.com]
Sent: Monday, December 18, 2006 11:22 AM
To: persistence_at_glassfish.dev.java.net
Subject: Re: byte [] primary keys...


Hi Adam,

  I looking in to integrating your suggested fix. I am starting by writing some tests.

  Could you provide either some test cases that demonstrate the issues or some detailed use cases?

Thanks,
Tom

Adam Leftik wrote:

> I have run into a couple of problems using byte [] types as primary
> keys. Not realizing the specification does not explicitly support this
> type mapping, we pursued this mapping strategy against a legacy data
> model which had RAW(16) pk's. Nontheless, weve run into problems when
> Entities with byte [] typed primary keys are used in relationships
> e.g.: Infinite loops, ClassCast Exceptions, and invalid Cache misses.
> IMHO, glassfish should support this use case and the JPA should
> explicitly support this use case in an a future specification
> revision.
>
> Folks often use fixed length RAW column types as primary keys when
> they need to store UUIDs, I personally, have run into this at least
> twice in the last your or so, and some of my collegues confirmed that
> this has become more, rather than less, common: the introduction of
> the java.util.UUID in Java 5, for example. Further, it seems more than
> reasonable, for an ORM solution to support fixed byte array mappings
> to a fixed RAW column --it is a quite natural mapping in my mind.
> While it is feasible for some folks to change data models e.g. storing
> the hex values in character based columns, this does not work for
> legacy data models due to significant data migration efforts, which in
> turn could hamper JPA adoption for these folks.
>
> After looking at the glassfish source code, it was clear that at some
> point this was supported, or at least intentded to be supported ,so I
> decided to resolve the issue and provide a fix for the broader
> community with the hope that it will integrated into the project. I
> have been testing this fix for a couple of weeks and have yet to
> encounter any issues. I am attaching the source for my byte [] fix. I
> did refactor a couple of things to enhance readability, and fixed a
> similar bug with char [] which should be supported too IMHO. If
> anyone else runs into any issues using this fix with byte/char [] pk's
> please drop me a note and would happy to try and provide a fix.
>
> Thanks,
> Adam