Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 9166F634116 for ; Tue, 12 May 2009 17:36:32 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 46059-03 for ; Tue, 12 May 2009 17:36:30 -0300 (ADT) Received: from mx3.hub.org (mx3.hub.org [206.223.169.73]) by mail.postgresql.org (Postfix) with ESMTP id 4B508634E51 for ; Tue, 12 May 2009 17:20:00 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx02.burntmail.com (mx02.burntmail.com [70.87.63.122]) by mx3.hub.org (Postfix) with ESMTP id B83E437B89D for ; Tue, 12 May 2009 17:19:59 -0300 (ADT) Received: from pool-173-79-69-35.washdc.fios.verizon.net ([173.79.69.35] helo=[127.0.0.1]) by mx02.burntmail.com with esmtpa (Exim 4.63) (envelope-from ) id 1M3yRt-0004go-Jf for pgsql-jdbc@postgresql.org; Tue, 12 May 2009 15:19:37 -0500 Message-ID: <4A09D9D9.6000306@burntmail.com> Date: Tue, 12 May 2009 16:19:37 -0400 From: Guy Rouillier User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: Enums - from java to jpa References: <321ed0a30905120701w740c3b5fp9e2623f9cf0b3be@mail.gmail.com> In-Reply-To: <321ed0a30905120701w740c3b5fp9e2623f9cf0b3be@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 090512-0, 05/12/2009), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200905/66 X-Sequence-Number: 19616 The Jasper wrote: > L.S., > > We are updating out application to make use of JPA. We have also > introduced postgres enums into our database. Naturally we also have > java enums which mirror the postgres enums. Now...how do I get JPA to > understand that it has different types at either end which are > actually the same. I mostly get ClassCastExceptions where PGObject is > being cast to String. I can't get rid of an enum definition at either > end, I'm stuck with that. So I need to make JPA understand how to map > from one to the other. We use Hibernate as our JPA implementation. > Our project is also using JPA via Hibernate, but with Oracle on the back end. Here is how we annotate our columns that access Java enums: @Column(name = "PREGION_ID", precision = 20, scale = 0, nullable = true) @Type(type = "com.masergy.sales360.persistence.GenericEnumUserType", parameters = { @Parameter(name = "enumClass", value = "com.masergy.sales360.client.model.OmsPricingRegionEnum"), @Parameter(name = "identifierMethod", value = "toInt"), @Parameter(name = "valueOfMethod", value = "fromInt") }) GenericEnumUserType implements UserType, ParameterizedType (Hibernate interfaces.) -- Guy Rouillier