Hibernate traces values of statement parameters also for large primitives byte array

Description

Instead of getting summurized resume for primitive byte array when logging query parameter value, hibernate log the whole byte array binary and i was getting something like that :

13:28:45,466 [wwsservices-catalina-exec-10] TRACE org.hibernate.type.descriptor.sql.BasicBinder: binding parameter [2] as [binary] - [[37, 80, 68, 70, 45, 49, 46, 52, ...

But the problem with this is when logging large byte array something about 3mb, it takes about 5 minutes before entity go to persist.
After investigation i found that is due to the PrimitiveByteArrayTypeDescriptor which madly implements the extractLoggableRepresentation method like this:

@Override
public String extractLoggableRepresentation(byte[] value) {
return (value == null) ? super.extractLoggableRepresentation( null ) : Arrays.toString( value );
}

So to fix this temporaly in my code i did something like that :

@SuppressWarnings("serial")
public class HibernateByteArrayType extends BinaryType {

public PrimitiveByteArrayType() {
setSqlTypeDescriptor(VarbinaryTypeDescriptor.INSTANCE);
setJavaTypeDescriptor(Descriptor.INSTANCE);
}

public static class Descriptor extends PrimitiveByteArrayTypeDescriptor {
public static final Descriptor INSTANCE = new Descriptor();

@Override
public String extractLoggableRepresentation(byte[] value) {
if (null == value) {
return super.extractLoggableRepresentation(value);
} else {
return "byte[" + readableFileSize(value.length) + "]";
}
}
}

public static String readableFileSize(long size) {
if(size <= 0) return "0";
final String[] units = new String[] { "B", "kB", "MB", "GB", "TB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
}

I have just override extractLoggableRepresentation(byte[] value) {..} to not return all byte array but just byte size and after that i got something like that :

2019-01-07 13:28:45,466 [wwsservices-catalina-exec-10] TRACE org.hibernate.type.descriptor.sql.BasicBinder: binding parameter [2] as [byte[3,2MB]].

So i would like to suggests you to take tis in to account in your next release

Thank you and sorry for my bad english

Environment

None

Assignee

Unassigned

Reporter

MEDOATINSA Augustin