HHH-8804 - Ability to use parametrized type as AttributeConverter type parameter
This commit is contained in:
parent
99e1250e4e
commit
48cafb2664
|
@ -26,12 +26,12 @@ package org.hibernate.cfg;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.lang.reflect.TypeVariable;
|
import java.lang.reflect.TypeVariable;
|
||||||
|
|
||||||
import javax.persistence.AttributeConverter;
|
import javax.persistence.AttributeConverter;
|
||||||
import javax.persistence.Converter;
|
import javax.persistence.Converter;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,7 +201,8 @@ public class AttributeConverterDefinition {
|
||||||
private static Class extractClass(Type type) {
|
private static Class extractClass(Type type) {
|
||||||
if ( type instanceof Class ) {
|
if ( type instanceof Class ) {
|
||||||
return (Class) type;
|
return (Class) type;
|
||||||
} else if (type instanceof ParameterizedType) {
|
}
|
||||||
|
else if ( type instanceof ParameterizedType ) {
|
||||||
return extractClass( ( (ParameterizedType) type ).getRawType() );
|
return extractClass( ( (ParameterizedType) type ).getRawType() );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
package org.hibernate.test.cfg;
|
package org.hibernate.test.type;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.AttributeConverter;
|
import javax.persistence.AttributeConverter;
|
||||||
|
|
||||||
import org.hibernate.cfg.AttributeConverterDefinition;
|
import org.hibernate.cfg.AttributeConverterDefinition;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests creation of AttributeConverterDefinition instances and
|
* Test the ability to interpret and understand AttributeConverter impls which
|
||||||
* the classes of the extracted type arguments
|
* use parameterized types as one of (typically the "attribute type") its parameter types.
|
||||||
*
|
*
|
||||||
* @author Svein Baardsen
|
* @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> {
|
public static class CustomAttributeConverter implements AttributeConverter<List<String>, Integer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer convertToDatabaseColumn(List<String> attribute) {
|
public Integer convertToDatabaseColumn(List<String> attribute) {
|
||||||
return attribute.size();
|
return attribute.size();
|
||||||
|
@ -31,7 +31,6 @@ public class AttributeConverterDefinitionTest extends BaseUnitTestCase {
|
||||||
public List<String> convertToEntityAttribute(Integer dbData) {
|
public List<String> convertToEntityAttribute(Integer dbData) {
|
||||||
return new ArrayList<String>(dbData);
|
return new ArrayList<String>(dbData);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
Loading…
Reference in New Issue