Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C22D217B36 for ; Fri, 27 Mar 2015 23:32:24 +0000 (UTC) Received: (qmail 40108 invoked by uid 500); 27 Mar 2015 23:32:24 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 40072 invoked by uid 500); 27 Mar 2015 23:32:24 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 40061 invoked by uid 99); 27 Mar 2015 23:32:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2015 23:32:24 +0000 X-ASF-Spam-Status: No, hits=-0.1 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of hal.hildebrand@me.com designates 17.158.236.237 as permitted sender) Received: from [17.158.236.237] (HELO nk11p04mm-asmtp002.mac.com) (17.158.236.237) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2015 23:31:56 +0000 Received: from [10.0.1.65] (c-69-181-28-87.hsd1.ca.comcast.net [69.181.28.87]) by nk11p04mm-asmtp002.mac.com (Oracle Communications Messaging Server 7.0.5.35.0 64bit (built Dec 4 2014)) with ESMTPSA id <0NLW0083J97U3L50@nk11p04mm-asmtp002.mac.com> for users@openjpa.apache.org; Fri, 27 Mar 2015 23:28:43 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.13.68,1.0.33,0.0.0000 definitions=2015-03-27_08:2015-03-27,2015-03-27,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=1 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1412110000 definitions=main-1503270230 From: Hal Hildebrand Content-type: multipart/alternative; boundary="Apple-Mail=_35A09518-395F-4851-A60E-06127AA6F17C" Subject: OpenJPA PostgreSQL UUID column Message-id: <3ED0768D-B0A2-4BFC-89B2-5EC26E68C3DF@me.com> Date: Fri, 27 Mar 2015 16:28:41 -0700 To: users@openjpa.apache.org MIME-version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) X-Mailer: Apple Mail (2.2070.6) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail=_35A09518-395F-4851-A60E-06127AA6F17C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I=E2=80=99m trying to use the native UUID type for PostgreSQL in my = OpenJPA model. I=E2=80=99m using OpenJPA 2.3.0 and at the current level = of the PostgreSQL JDBC driver. I=E2=80=99ve tried to accomplish this several times and I=E2=80=99ve = gotten a bit further this time. I created a ValueHolder (see attached = file) and it does what I believe is the correct setup for this type. I = use this as the strategy for the column - i.e. : @Strategy("com.chiralbehaviors.CoRE.openjpa.UuidValueHandler") I=E2=80=99ve validated via breakpoint that the UuidValueHolder is indeed = called in setup and when converting values. I=E2=80=99m at the point of = trying to do an insert, and regardless of whether I use an actual UUID = as the return mapping (i.e. no transform) or a string (UUID.toString()) = I get the same error: ERROR: column "id" is of type uuid but expression is of type bytea Hint: You will need to rewrite or cast the expression. Position: 93 {prepstmnt 1848199707=20 INSERT INTO ruleform.agency (id, notes, update_date, description, name,=20= updated_by)=20 VALUES (?, ?, ?, ?, ?, ?)=20 [params=3D(byte[]) [B@9ac8b5b, (null) null, (Timestamp) 2015-03-27 = 15:20:05.921, (null) null, (String) CoRE, (byte[]) [B@15b17c95]} = [code=3D0, state=3D42804] I believe that this error comes from the postgres jdbc driver, not = openJPA. I=E2=80=99ve even tried using PGObject, which surprisingly = works just fine, but throws the same error. In my google searches, this has come across as a typical problem, and = I=E2=80=99ve only found solutions for this (hypothesized) for Toplink = and Hibernate. The one thing I could find suggested writing the = ValueHolder and that does work up until the point I try to actually = insert in JDBC land. Note that the UUID is being passed as a byte array. So my question is, am I doing anything incorrect? Missing something? = =46rom the error message, it would appear postgresql wants me to cast = the result, but I=E2=80=99m not sure how to accomplish that in OpenJPA. = It could simply be a red herring. Any help appreciated, as I simply can=E2=80=99t find a working solution = via Der Google -Hal= --Apple-Mail=_35A09518-395F-4851-A60E-06127AA6F17C Content-Type: multipart/mixed; boundary="Apple-Mail=_BB7E958F-0301-4A70-8AAC-4F55F9E86BAA" --Apple-Mail=_BB7E958F-0301-4A70-8AAC-4F55F9E86BAA Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii --Apple-Mail=_BB7E958F-0301-4A70-8AAC-4F55F9E86BAA Content-Disposition: attachment; filename=UuidValueHandler.java Content-Type: application/octet-stream; name="UuidValueHandler.java" Content-Transfer-Encoding: 7bit /** * (C) Copyright 2015 Chiral Behaviors, LLC. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.chiralbehaviors.CoRE.openjpa; import java.sql.Types; import org.apache.openjpa.jdbc.identifier.DBIdentifier; import org.apache.openjpa.jdbc.kernel.JDBCStore; import org.apache.openjpa.jdbc.meta.ValueMapping; import org.apache.openjpa.jdbc.meta.strats.AbstractValueHandler; import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.schema.ColumnIO; import org.apache.openjpa.meta.JavaTypes; public class UuidValueHandler extends AbstractValueHandler { private static final long serialVersionUID = 1L; /** * @deprecated */ @Deprecated @Override public Column[] map(ValueMapping vm, String name, ColumnIO io, boolean adapt) { return map(vm, DBIdentifier.newColumn(name, false), io, adapt); } public Column[] map(ValueMapping vm, DBIdentifier name, ColumnIO io, boolean adapt) { Column col = new Column(); col.setIdentifier(name); col.setJavaType(JavaTypes.OBJECT); col.setType(Types.OTHER); col.setTypeIdentifier(DBIdentifier.newColumnDefinition("uuid")); return new Column[] { col }; } public boolean isVersionable() { return true; } @Override public Object toDataStoreValue(ValueMapping vm, Object object, JDBCStore store) { return object; } @Override public Object toObjectValue(ValueMapping vm, Object val) { return val; } } --Apple-Mail=_BB7E958F-0301-4A70-8AAC-4F55F9E86BAA Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

I=E2=80=99m trying to use the native = UUID type for PostgreSQL in my OpenJPA model.  I=E2=80=99m using = OpenJPA 2.3.0 and at the current level of the PostgreSQL JDBC = driver.

I=E2=80=99= ve tried to accomplish this several times and I=E2=80=99ve gotten a bit = further this time.  I created a ValueHolder (see attached file) and = it does what I believe is the correct setup for this type.  I use = this as the strategy for the column - i.e. :

= @Strategy("com.chiralbehaviors.CoRE.openjpa.UuidValueHandler")

I=E2=80=99ve = validated via breakpoint that the UuidValueHolder is indeed called in = setup and when converting values.  I=E2=80=99m at the point of = trying to do an insert, and regardless of whether I use an actual UUID = as the return mapping (i.e. no transform) or a string (UUID.toString()) = I get the same error:

ERROR: column "id" is of type = uuid but expression is of type bytea
  Hint: You = will need to rewrite or cast the expression.
  Position: = 93 {prepstmnt 1848199707 
INSERT INTO ruleform.agency (id, = notes, update_date, description, name, 
    =     updated_by) 
    VALUES (?, ?, ?, = ?, ?, ?) 
[params=3D(byte[]) [B@9ac8b5b, = (null) null, (Timestamp) 2015-03-27 15:20:05.921, (null) null, (String) = CoRE, (byte[]) [B@15b17c95]} [code=3D0, = state=3D42804]

I believe that this error comes from = the postgres jdbc driver, not openJPA.  I=E2=80=99ve even tried = using PGObject, which surprisingly works just fine, but throws the same = error.

In my = google searches, this has come across as a typical problem, and I=E2=80=99= ve only found solutions for this (hypothesized) for Toplink and = Hibernate.  The one thing I could find suggested writing the = ValueHolder and that does work up until the point I try to actually = insert in JDBC land.

Note that the UUID is being passed as a byte array.

So my question is, am I = doing anything incorrect?  Missing something?  =46rom the = error message, it would appear postgresql wants me to cast the result, = but I=E2=80=99m not sure how to accomplish that in OpenJPA.  It = could simply be a red herring.

Any help appreciated, as I simply = can=E2=80=99t find a working solution via Der Google

-Hal
= --Apple-Mail=_BB7E958F-0301-4A70-8AAC-4F55F9E86BAA-- --Apple-Mail=_35A09518-395F-4851-A60E-06127AA6F17C--