Permalink
Browse files

HHH-7930 Hibernate will crash with (custom) enum types when running w…

…ith a logback.xml in debug mode
  • Loading branch information...
1 parent c52864d commit c1317346acc5438d100c4de1664b67c449f2183e @stliu stliu committed Jan 30, 2013
Showing with 11 additions and 1 deletion.
  1. +11 −1 hibernate-core/src/main/java/org/hibernate/type/EnumType.java
@@ -37,11 +37,13 @@
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 @@
* @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 Object fromXMLString(String xmlValue) {
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;

0 comments on commit c131734

Please sign in to comment.