HHH-8804 - Ability to use parametrized type as AttributeConverter type parameter

(cherry picked from commit 48cafb2664)
This commit is contained in:
Steve Ebersole 2015-05-12 23:34:20 -05:00
parent c2100677f1
commit 021122a2dc
2 changed files with 18 additions and 18 deletions

View File

@ -26,11 +26,11 @@ package org.hibernate.cfg;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import javax.persistence.AttributeConverter;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.jboss.logging.Logger;
/**
@ -125,7 +125,8 @@ public class AttributeConverterDefinition {
private static Class extractClass(Type type) {
if ( type instanceof Class ) {
return (Class) type;
} else if (type instanceof ParameterizedType) {
}
else if ( type instanceof ParameterizedType ) {
return extractClass( ( (ParameterizedType) type ).getRawType() );
}
return null;

View File

@ -1,27 +1,27 @@
package org.hibernate.test.cfg;
import static org.junit.Assert.assertEquals;
package org.hibernate.test.type;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.AttributeConverter;
import org.hibernate.cfg.AttributeConverterDefinition;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Tests creation of AttributeConverterDefinition instances and
* the classes of the extracted type arguments
* Test the ability to interpret and understand AttributeConverter impls which
* use parameterized types as one of (typically the "attribute type") its parameter types.
*
* @author Svein Baardsen
* @author Steve Ebersole
*/
public class AttributeConverterDefinitionTest extends BaseUnitTestCase {
public class ParameterizedAttributeConverterParameterTypeTest extends BaseUnitTestCase {
public static class CustomAttributeConverter implements AttributeConverter<List<String>, Integer> {
@Override
public Integer convertToDatabaseColumn(List<String> attribute) {
return attribute.size();
@ -31,7 +31,6 @@ public class AttributeConverterDefinitionTest extends BaseUnitTestCase {
public List<String> convertToEntityAttribute(Integer dbData) {
return new ArrayList<String>(dbData);
}
}
@Test