HHH-7930 Hibernate will crash with (custom) enum types when running with a logback.xml in debug mode

This commit is contained in:
Strong Liu 2013-01-30 17:10:11 +08:00
parent c52864d188
commit c1317346ac
1 changed files with 11 additions and 1 deletions

View File

@ -37,11 +37,13 @@ import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.usertype.DynamicParameterizedType;
import org.hibernate.usertype.EnhancedUserType;
import org.hibernate.usertype.LoggableUserType;
/**
* Value type mapper for enumerations.
@ -66,7 +68,7 @@ import org.hibernate.usertype.EnhancedUserType;
* @author Steve Ebersole
*/
@SuppressWarnings("unchecked")
public class EnumType implements EnhancedUserType, DynamicParameterizedType, Serializable {
public class EnumType implements EnhancedUserType, DynamicParameterizedType,LoggableUserType, Serializable {
private static final Logger LOG = Logger.getLogger( EnumType.class.getName() );
public static final String ENUM = "enumClass";
@ -313,6 +315,14 @@ public class EnumType implements EnhancedUserType, DynamicParameterizedType, Ser
return enumValueMapper.fromXMLString( xmlValue );
}
@Override
public String toLoggableString(Object value, SessionFactoryImplementor factory) {
if ( enumValueMapper != null ) {
return enumValueMapper.toXMLString( (Enum) value );
}
return value.toString();
}
private static interface EnumValueMapper extends Serializable {
public int getSqlType();
public Enum getValue(ResultSet rs, String[] names) throws SQLException;