Re: Enums - from java to jpa

From: Guy Rouillier <guyr-ml1(at)burntmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Enums - from java to jpa
Date: 2009-05-12 20:19:37
Message-ID: 4A09D9D9.6000306@burntmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2009-05-13 00:44:08 Re: pooled prepared statements
Previous Message John Lister 2009-05-12 19:38:51 Re: pooled prepared statements