Thanks for the reply Rick. That does the trick for one field, but this class is used heavily throughout the model. If possible I'd like to create a custom field mapping, so that every time a UUID is encountered, this mapping happens automatically. I've created a custom field mapping.
public class UUIDValueHandler extends ByteArrayValueHandler { @Override public Object toDataStoreValue(ValueMapping vm, Object val, JDBCStore store) { final byte[] data = UUIDSerializer.toBytes((com.eaio.uuid.UUID) val); return super.toDataStoreValue(vm, data, store); } @Override public Object toObjectValue(ValueMapping vm, Object val) { byte[] data = (byte[]) val; final UUID uuid = UUIDSerializer.fromBytes(data); return uuid; } } However, it's not clear to me how to configure this as a plugin via the JPA configuration. I searched through the documentation, but I can't find any examples for how to do this. I referenced this section. http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#ref_guide_mapping_custom_field_conf However when I navigate to the reference of section 4 it takes me to this section. http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#ref_guide_mapping_defaults Should I define a property as follows? <property name="openjpa.jdbc.MappingDefaults" value="FieldStrategies='com.eaio.uuid.UUID=com.spidertracks.aviator.dataaccess.jpa.mysql.UUIDValueHandler'"/> On 19 March 2014 08:56, Rick Curtis <curti...@gmail.com> wrote: > 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 <t...@spidertracks.com> 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* >