@@ -0,0 +1,2661 @@
+package com.voodoodyne.postguice.usertype;%0A%0Aimport com.google.common.base.Objects;%0Aimport org.hibernate.HibernateException;%0Aimport org.hibernate.engine.spi.SharedSessionContractImplementor;%0Aimport org.hibernate.usertype.UserType;%0A%0Aimport java.io.Serializable;%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.sql.Types;%0A%0A/**%0A * Hibernate %7B@link UserType%7D that maps to a simple string column. Your class must be immutable.%0A *%0A * Create a subclass for any specific type you want converted to JSON.%0A *%0A * @param %3CT%3E is the type of the class you want to convert to string with this%0A */%0Aabstract public class SimpleStringUserType%3CT extends Serializable%3E implements UserType, Serializable %7B%0A%0A%09private static final long serialVersionUID = 2020526952561198860L;%0A%0A%09private static final int%5B%5D SQL_TYPES = new int%5B%5D%7BTypes.VARCHAR%7D;%0A%0A%09private final Class%3CT%3E classType;%0A%0A%09public SimpleStringUserType(final Class%3CT%3E classType) %7B%0A%09%09this.classType = classType;%0A%09%7D%0A%0A%09/** Implement this to convert from the string value in the column to your user type */%0A%09protected abstract T construct(final String value);%0A%0A%09@Override%0A%09public Object assemble(Serializable cached, Object owner) throws HibernateException %7B%0A%09%09return cached;%0A%09%7D%0A%0A%09@Override%0A%09public Object deepCopy(Object value) throws HibernateException %7B%0A%09%09return value;%0A%09%7D%0A%0A%09@Override%0A%09public Serializable disassemble(Object value) throws HibernateException %7B%0A%09%09return (Serializable)value;%0A%09%7D%0A%0A%09@Override%0A%09public boolean equals(Object x, Object y) throws HibernateException %7B%0A%09%09return Objects.equal(x, y);%0A%09%7D%0A%0A%09@Override%0A%09public int hashCode(Object x) throws HibernateException %7B%0A%09%09return Objects.hashCode(x);%0A%09%7D%0A%0A%09@Override%0A%09public boolean isMutable() %7B%0A%09%09return false;%0A%09%7D%0A%0A%09@Override%0A%09public Object nullSafeGet(final ResultSet rs, final String%5B%5D names, final SharedSessionContractImplementor session, final Object owner) throws HibernateException, SQLException %7B%0A%09%09String value = rs.getString(names%5B0%5D);%0A%0A%09%09if (value == null) %7B%0A%09%09%09return null;%0A%09%09%7D else %7B%0A%09%09%09return construct(value);%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void nullSafeSet(final PreparedStatement st, final Object value, final int index, final SharedSessionContractImplementor session) throws HibernateException, SQLException %7B%0A%09%09if (value == null) %7B%0A%09%09%09st.setNull(index, Types.VARCHAR);%0A%09%09%7D else %7B%0A%09%09%09st.setString(index, value.toString());%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public Object replace(Object original, Object target, Object owner) throws HibernateException %7B%0A%09%09return original;%0A%09%7D%0A%0A%09@Override%0A%09public Class%3C?%3E returnedClass() %7B%0A%09%09return this.classType;%0A%09%7D%0A%0A%09@Override%0A%09public int%5B%5D sqlTypes() %7B%0A%09%09return SQL_TYPES;%0A%09%7D%0A%7D

Add a simple string user type