HHH-7643 - java.io.NotSerializableException org.hibernate.type.EnumType
(cherry picked from commit 2158bec47c
)
This commit is contained in:
parent
695213568d
commit
b69c554f9e
|
@ -313,7 +313,7 @@ public class EnumType implements EnhancedUserType, DynamicParameterizedType, Ser
|
|||
return enumValueMapper.fromXMLString( xmlValue );
|
||||
}
|
||||
|
||||
private static interface EnumValueMapper {
|
||||
private static interface EnumValueMapper extends Serializable {
|
||||
public int getSqlType();
|
||||
public Enum getValue(ResultSet rs, String[] names) throws SQLException;
|
||||
public void setValue(PreparedStatement st, Enum value, int index) throws SQLException;
|
||||
|
@ -345,7 +345,7 @@ public class EnumType implements EnhancedUserType, DynamicParameterizedType, Ser
|
|||
}
|
||||
}
|
||||
|
||||
private class OrdinalEnumValueMapper extends EnumValueMapperSupport implements EnumValueMapper {
|
||||
private class OrdinalEnumValueMapper extends EnumValueMapperSupport implements EnumValueMapper, Serializable {
|
||||
private transient Enum[] enumsByOrdinal;
|
||||
|
||||
@Override
|
||||
|
@ -416,7 +416,7 @@ public class EnumType implements EnhancedUserType, DynamicParameterizedType, Ser
|
|||
}
|
||||
}
|
||||
|
||||
private class NamedEnumValueMapper extends EnumValueMapperSupport implements EnumValueMapper {
|
||||
private class NamedEnumValueMapper extends EnumValueMapperSupport implements EnumValueMapper, Serializable {
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
return Types.VARCHAR;
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.enums;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.internal.util.SerializationHelper;
|
||||
import org.hibernate.type.EnumType;
|
||||
import org.hibernate.usertype.DynamicParameterizedType;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TestEnumTypeSerialization extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testSerializability() {
|
||||
{
|
||||
// test ordinal mapping
|
||||
EnumType enumType = new EnumType();
|
||||
Properties properties = new Properties();
|
||||
properties.put( EnumType.ENUM, UnspecifiedEnumTypeEntity.E1.class.getName() );
|
||||
enumType.setParameterValues( properties );
|
||||
assertTrue( enumType.isOrdinal() );
|
||||
SerializationHelper.clone( enumType );
|
||||
}
|
||||
|
||||
{
|
||||
// test named mapping
|
||||
EnumType enumType = new EnumType();
|
||||
Properties properties = new Properties();
|
||||
properties.put( EnumType.ENUM, UnspecifiedEnumTypeEntity.E1.class.getName() );
|
||||
properties.put( EnumType.NAMED, "true" );
|
||||
enumType.setParameterValues( properties );
|
||||
assertFalse( enumType.isOrdinal() );
|
||||
SerializationHelper.clone( enumType );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue