Todd -
Take a look at @Externalizer/@Factory in the user manual[1]. Below is a
snippet of code where I have a String field in my Entity, but the backing
column in the DB is an int. The Externalizer/Factory methods convert values
from/to the database. Let me know how this goes.
Thanks,
Rick
@Id
@Externalizer("org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1.toDb")
@Factory("org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1.fromDb")
private String intField;
public static int toDb(String val){
return Integer.valueOf(val);
}
public static String fromDb(int val) {
return String.valueOf(val);
}
[1]
http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#ref_guide_pc_extern
On Wed, Mar 19, 2014 at 12:10 AM, Todd Nine <[email protected]> wrote:
> Hi all,
> We're migrating from a Key/Value system to MySQL for some components of
> our system for easier administration and maintenance. As part of this
> migration, we need to retain the time UUIDs that have been generated for
> primary keys. I'm having a hard time mapping this. I have the following.
>
> @Id
> @Column( columnDefinition = "BINARY(16)", length = 16 )
> private UUID id;
>
> However this always seems to fail. I'm on the latest MySQL version 5.6.16
> GA and Open JPA 2.2.2 I've found this old thread, but it's not quite what
> I'm looking for. I'm really struggling to find the documentation on how to
> declare and implement custom type converters. Converting a UUID to a binary
> array of length 16 is trivial, as is creating a new UUID instance from
> those bytes. I'm just not sure how to plug in to the JPA framework to make
> it happen. Any advice would be greatly appreciated.
>
> Thanks,
> Todd
>
--
*Rick Curtis*