Paul - I was able to write a small unit test that worked for the scenario you have described. Take a look at a couple snippets from my unit test and see if they help you out.
@Entity @IdClass(ByteArrayIdClass.class) public class ByteArrayIdentityEntity { @Id @Column(columnDefinition="CHAR(16) FOR BIT DATA NOT NULL") // type 1004 size -1 should be size 0 private byte[] id; ..... // Omitted getters / setters / <init> / hashCode / equals public class ByteArrayIdClass { private byte[] id; .... // Omitted getters / setters / <init> / hashCode / equals Let me know if this works for you... If so, I'll update my SO answer. Thanks, Rick On Mon, Oct 22, 2012 at 12:30 PM, Paul Holding <p...@pholding.co.uk> wrote: > I have a requirement to read and write records using OpenJPA to a table in > a > DB2 database where the primary key is a UUID stored in a column defined as > "char(16) bit for data". > > The JPA entity class for the entity I'm trying to persist references an > identity class which contains the byte array that will be used for the > primary key. However whenever I try to persist the record to the table DB2 > returns the error: > > Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: The value of > input variable, expression or parameter number "1" cannot be used because > of > its data type.. SQLCODE=-301, SQLSTATE=07006, DRIVER=3.63.123 {prepstmnt > -937290353 INSERT INTO FRAMEWORK.SITE3 (ID, SITE_ADDRESS, SITE_NAME, > ROW_VERSION) VALUES (?, ?, ?, ?) [params=(InputStream) > java.io.ByteArrayInputStream@94c7f78e, (String) test, (String) test, (int) > 1]} [code=-301, state=07006] > > The full stacktrace is available at http://pastebin.com/QFxYgzDH > > The identity class is a copy of https://gist.github.com/1153724 > > After a bit of Google searching I've found JIRA OPENJPA-922 which has a > very > similar error message, although it says the fix was applied in OpenJPA > version 2.0.0-M3 whilst I'm running a later version of OpenJPA. > > The entity class and identity class are part of an EJB which is running on > WebSphere version 8.5 using the version of OpenJPA provided by the > container > which I believe is 2.2.1. > > Would someone please be able to confirm whether I should be able to write a > byte array containing a UUID into a table in a DB2 database where the > column > is defined as "char(16) bit for data" using OpenJPA and if so, suggest > where > I'm going wrong as I can't see how to resolve this problem? > > > -- *Rick Curtis*