You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Roy Smith <ro...@primetext.com> on 2007/12/02 23:47:31 UTC
Custom data types
I've got a custom (PostgreSQL) data type
*create* type couk_cleverthinking_gwappo_db_Money *as* (local_value *numeric*(11,2),mnemonic *char*(3));
and a corresponding Class definition.
public class Money extends PGobject implements SQLData, Serializable, Cloneable{
public BigDecimal localValue;
public String currencyMnemonic;
.
.
etc
.
.
}
After a bit of effort I got this working in JDBC(the key being PGConnection.addType()).
Please could somebody give me some pointers on how to go about incorporating this custom type/mapping into OpenJPA.
Eg. is this a Value Handler or Class Strategy problem (or am I barking up the wrong tree altogether)?
very best wishes
Roy
Re: Custom data types
Posted by pl...@gmail.com.
Hi,
I think ValueHandler will be the way to go. This will let you use the
new type as a field, as a member of a list, and as a key or value in a
map.
Additionally, you'll be able to use instances of the new type in queries.
There is a sample ValueHandler for Points that should map well to your needs.
-Patrick
On 12/2/07, Roy Smith <ro...@primetext.com> wrote:
> I've got a custom (PostgreSQL) data type
>
> *create* type couk_cleverthinking_gwappo_db_Money *as* (local_value
> *numeric*(11,2),mnemonic *char*(3));
>
> and a corresponding Class definition.
>
> public class Money extends PGobject implements SQLData, Serializable,
> Cloneable{
> public BigDecimal localValue;
> public String currencyMnemonic;
> .
> .
> etc
> .
> .
> }
>
>
> After a bit of effort I got this working in JDBC(the key being
> PGConnection.addType()).
>
> Please could somebody give me some pointers on how to go about incorporating
> this custom type/mapping into OpenJPA.
> Eg. is this a Value Handler or Class Strategy problem (or am I barking up
> the wrong tree altogether)?
>
>
> very best wishes
> Roy
>
>
>
>
>
>
--
Patrick Linskey
202 669 5907
Re: Custom data types
Posted by Roy Smith <ro...@primetext.com>.
Woohoo - fixed it!!!!
Kinda
I solved my problem by switching to Toplink11g.
By adding the 2 new annotations TypeConverter and Convert, my
application now works.
@TypeConverter( name = "money", dataType = PGobject.class,
objectType = Money.class )
@Convert("money")
@Column(name = "price", unique = false, nullable = true, insertable
= true, updatable = true)
private Money price;
Now if somebody could help me out by explaining how to do the same thing
in OpenJPA, that would really make my day.
very best wishes
Roy
In case anybody's wondering, it seems that the PostgreSQL JDBC driver
doesn't support the standard SQLData Interface so one has to use
PGobject instead.
Re: Custom data types
Posted by pl...@gmail.com.
Hi,
I think that you should be using the regular Java type name; are there
really underscores and no package in the class ne?
You can always specify a strategy for a particular field with the
@Strategy annotation as well.
-Patrick
On 12/3/07, Roy Smith <ro...@primetext.com> wrote:
> Thanks for the pointer, Patrick.
>
> I've created a MoneyValueHandler based on the PointHandler example. So
> far so good.
> Now I'm struggling to see how I configure my handler into OpenJPA.
>
> I've tried adding this line to my persistence.xml
> <property name="openjpa.jdbc.MappingDefaults"
> value="FieldStrategy='couk_cleverthinking_gwappo_db_money=couk.cleverthinking.gwappo.db.MoneyValueHandler'"/>
> but it seems to have no effect, ie. my handler is not being invoked.
>
> I'm guessing I've got the configuration wrong or missed a step, but I
> can't seem to find any examples on how to achieve this.
>
> very best wishes
> Roy
>
>
--
Patrick Linskey
202 669 5907
Re: Custom data types
Posted by Roy Smith <ro...@primetext.com>.
Thanks for the pointer, Patrick.
I've created a MoneyValueHandler based on the PointHandler example. So
far so good.
Now I'm struggling to see how I configure my handler into OpenJPA.
I've tried adding this line to my persistence.xml
<property name="openjpa.jdbc.MappingDefaults"
value="FieldStrategy='couk_cleverthinking_gwappo_db_money=couk.cleverthinking.gwappo.db.MoneyValueHandler'"/>
but it seems to have no effect, ie. my handler is not being invoked.
I'm guessing I've got the configuration wrong or missed a step, but I
can't seem to find any examples on how to achieve this.
very best wishes
Roy