EmptyStringUserType implements UserType { @Override public boolean equals(Object x, Object y) throws HibernateException { if (x == y) { return true; } if (x == null) { return ((String) y).length() == 0; } else if (y == null) { return ((String) x).length() == 0; } return x.equals(y); }  @Override int[] sqlTypes(); @Override Class<String> returnedClass(); @Override boolean equals(Object x, Object y); @Override int hashCode(Object x); @Override Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor si, Object owner); @Override void nullSafeSet(PreparedStatement st, Object value, int index,
        SharedSessionContractImplementor si); @Override Object deepCopy(Object value); @Override boolean isMutable(); @Override Serializable disassemble(Object value); @Override Object assemble(Serializable cached, Object owner); @Override Object replace(Object original, Object target, Object owner);  }
@Test public void testEqualsNullAndEmptyString() { String x = null; String y = ""; EmptyStringUserType ut = new EmptyStringUserType(); assertTrue(ut.equals(x, y)); x = ""; y = null; assertTrue(ut.equals(x, y)); }
@Test public void testEqualsNormal() { String x = "Hello"; String y = "Hello"; EmptyStringUserType ut = new EmptyStringUserType(); assertTrue(ut.equals(x, y)); y = "World"; assertFalse(ut.equals(x, y)); }