Closed amrnablus closed 5 years ago
Thank you very much for your message.
jOOU is just a library providing some data types. It has nothing to do with JPA. In order to make JPA support jOOU types, you will need to provide vendor-specific type mappings (e.g. UserType
in Hibernate). This isn't something jOOU would want to offer.
Thanks Luka, i ended up using a convertor. I will post the details here in case someone runs into the same issue: In the JPA Entity:
@Convert(converter = UBytesListConverter.class)
private UByte[] data;
The convertor class:
@Converter
public class UBytesListConverter implements AttributeConverter<UByte[], byte[]> {
@Override
public byte[] convertToDatabaseColumn(UByte[] bytesList) {
byte[] res = new byte[bytesList.length];
for( int i=0; i<bytesList.length; i++ ) {
res[i] = bytesList[i].byteValue();
}
return res;
}
@Override
public UByte[] convertToEntityAttribute(byte[] entity) {
UByte[] res = new UByte[entity.length];
for( int i=0; i<entity.length; i++ ) {
res[i] = ubyte(entity[i]);
}
return res;
}
}
Ah yes, of course. That's a viable option as well. Thanks for documenting this here.
Do note, however, that a UByte[]
might take significantly more memory in your Java client, than a byte[]
Yeah we gotta pay for quality my friend haha :P
Expected behavior and actual behavior:
I get an error saying: Incorrect string value: '\x00\x00...' for column ...
Steps to reproduce the problem:
Create a JPA entity with a field of type UByte[] and persist it
Versions: