I made my own CharArrayType (see below) and put @Type(type="my.package.CharArrayType") on the getters of my arrays.
Code:
package my.package;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
/**
* Fixes the build-in Hibernate CharArray type.<br />
* See <a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-2606">Jira issue</a>
*/
public class CharArrayType implements UserType {
private static final int[] SQL_TYPES = { Types.VARCHAR };
public int[] sqlTypes() {
return SQL_TYPES;
}
public Class returnedClass() {
return char[].class;
}
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
throws HibernateException, SQLException {
String value = (String) Hibernate.STRING.nullSafeGet(resultSet, names);
return value != null ? value.toCharArray() : null;
}
public void nullSafeSet(PreparedStatement preparedStatement, Object value,
int index) throws HibernateException, SQLException {
Hibernate.STRING.nullSafeSet(preparedStatement,
value != null ? new String((char[]) value) : null, index);
}
public Object deepCopy(Object value) throws HibernateException {
if(value == null){
return null;
}
char[] chars = (char[]) value;
char[] copy = new char[chars.length];
System.arraycopy(chars, 0, copy, 0, chars.length);
return copy;
}
public boolean isMutable() {
return true;
}
public Object assemble(Serializable cached, Object owner)
throws HibernateException {
return cached;
}
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
}
public Object replace(Object original, Object target, Object owner)
throws HibernateException {
return original;
}
public int hashCode(Object x) throws HibernateException {
return x.hashCode();
}
public boolean equals(Object x, Object y) throws HibernateException {
return Arrays.equals((char[]) x, (char[]) y);
}
}