HHH-12978 Properly initialize the converters on deserialization
This commit is contained in:
parent
ae2da95f55
commit
9ead103044
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.model.convert.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -31,18 +33,17 @@ public class NamedEnumValueConverter<E extends Enum> implements EnumValueConvert
|
|||
|
||||
private final EnumJavaTypeDescriptor<E> enumJavaDescriptor;
|
||||
|
||||
private final transient ValueExtractor<E> valueExtractor;
|
||||
private transient ValueExtractor<E> valueExtractor;
|
||||
|
||||
private final transient ValueBinder<String> valueBinder;
|
||||
private transient ValueBinder<String> valueBinder;
|
||||
|
||||
public NamedEnumValueConverter(EnumJavaTypeDescriptor<E> enumJavaDescriptor) {
|
||||
this.enumJavaDescriptor = enumJavaDescriptor;
|
||||
this.valueExtractor = VarcharTypeDescriptor.INSTANCE.getExtractor( enumJavaDescriptor );
|
||||
this.valueBinder = VarcharTypeDescriptor.INSTANCE.getBinder( StringTypeDescriptor.INSTANCE );
|
||||
this.valueExtractor = createValueExtractor( enumJavaDescriptor );
|
||||
this.valueBinder = createValueBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public E toDomainValue(String relationalForm) {
|
||||
return enumJavaDescriptor.fromName( relationalForm );
|
||||
}
|
||||
|
@ -79,4 +80,19 @@ public class NamedEnumValueConverter<E extends Enum> implements EnumValueConvert
|
|||
public String toSqlLiteral(Object value) {
|
||||
return String.format( Locale.ROOT, "'%s'", ( (E) value ).name() );
|
||||
}
|
||||
|
||||
private static <T extends Enum> ValueExtractor<T> createValueExtractor(EnumJavaTypeDescriptor<T> enumJavaDescriptor) {
|
||||
return VarcharTypeDescriptor.INSTANCE.getExtractor( enumJavaDescriptor );
|
||||
}
|
||||
|
||||
private static ValueBinder<String> createValueBinder() {
|
||||
return VarcharTypeDescriptor.INSTANCE.getBinder( StringTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException {
|
||||
stream.defaultReadObject();
|
||||
|
||||
this.valueExtractor = createValueExtractor( enumJavaDescriptor );
|
||||
this.valueBinder = createValueBinder();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.model.convert.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -29,18 +31,17 @@ public class OrdinalEnumValueConverter<E extends Enum> implements EnumValueConve
|
|||
|
||||
private final EnumJavaTypeDescriptor<E> enumJavaDescriptor;
|
||||
|
||||
private final transient ValueExtractor<E> valueExtractor;
|
||||
private transient ValueExtractor<E> valueExtractor;
|
||||
|
||||
private final transient ValueBinder<Integer> valueBinder;
|
||||
private transient ValueBinder<Integer> valueBinder;
|
||||
|
||||
public OrdinalEnumValueConverter(EnumJavaTypeDescriptor<E> enumJavaDescriptor) {
|
||||
this.enumJavaDescriptor = enumJavaDescriptor;
|
||||
this.valueExtractor = IntegerTypeDescriptor.INSTANCE.getExtractor( enumJavaDescriptor );
|
||||
this.valueBinder = IntegerTypeDescriptor.INSTANCE.getBinder( org.hibernate.type.descriptor.java.IntegerTypeDescriptor.INSTANCE );
|
||||
this.valueExtractor = createValueExtractor( enumJavaDescriptor );
|
||||
this.valueBinder = createValueBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public E toDomainValue(Integer relationalForm) {
|
||||
return enumJavaDescriptor.fromOrdinal( relationalForm );
|
||||
}
|
||||
|
@ -77,4 +78,19 @@ public class OrdinalEnumValueConverter<E extends Enum> implements EnumValueConve
|
|||
public String toSqlLiteral(Object value) {
|
||||
return Integer.toString( ( (E) value ).ordinal() );
|
||||
}
|
||||
|
||||
private static <T extends Enum> ValueExtractor<T> createValueExtractor(EnumJavaTypeDescriptor<T> enumJavaDescriptor) {
|
||||
return IntegerTypeDescriptor.INSTANCE.getExtractor( enumJavaDescriptor );
|
||||
}
|
||||
|
||||
private static ValueBinder<Integer> createValueBinder() {
|
||||
return IntegerTypeDescriptor.INSTANCE.getBinder( org.hibernate.type.descriptor.java.IntegerTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException {
|
||||
stream.defaultReadObject();
|
||||
|
||||
this.valueExtractor = createValueExtractor( enumJavaDescriptor );
|
||||
this.valueBinder = createValueBinder();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue