diff --git a/jOOQ/src/main/java/org/jooq/impl/JPAConverter.java b/jOOQ/src/main/java/org/jooq/impl/JPAConverter.java index 3b7bba3606..79d4f97506 100644 --- a/jOOQ/src/main/java/org/jooq/impl/JPAConverter.java +++ b/jOOQ/src/main/java/org/jooq/impl/JPAConverter.java @@ -42,6 +42,7 @@ import java.lang.reflect.Method; import javax.persistence.AttributeConverter; import org.jooq.exception.MappingException; +import org.jooq.tools.JooqLogger; import org.jooq.tools.reflect.Reflect; @@ -63,6 +64,7 @@ public final class JPAConverter extends AbstractConverter { * Generated UID */ private static final long serialVersionUID = -8359212595180862077L; + private static final JooqLogger log = JooqLogger.getLogger(JPAConverter.class); private final AttributeConverter delegate; @@ -79,18 +81,40 @@ public final class JPAConverter extends AbstractConverter { @SuppressWarnings("unchecked") private static final Class fromType(Class> klass) { - for (Method method : klass.getMethods()) + Method candidate = null; + + // [#10951] Try finding the bridge method, skip the inherited method if applicable + for (Method method : klass.getDeclaredMethods()) if ("convertToDatabaseColumn".equals(method.getName())) - return (Class) method.getReturnType(); + if (method.getReturnType() == Object.class) + candidate = method; + else + return (Class) method.getReturnType(); + + if (candidate != null) { + log.warn("Couldn't find bridge method to detect generic type bound for " + klass.getName() + "::convertToDatabaseColumn"); + return (Class) candidate.getReturnType(); + } throw new IllegalArgumentException(); } @SuppressWarnings("unchecked") private static final Class toType(Class> klass) { - for (Method method : klass.getMethods()) + Method candidate = null; + + // [#10951] Try finding the bridge method, skip the inherited method if applicable + for (Method method : klass.getDeclaredMethods()) if ("convertToEntityAttribute".equals(method.getName())) - return (Class) method.getReturnType(); + if (method.getReturnType() == Object.class) + candidate = method; + else + return (Class) method.getReturnType(); + + if (candidate != null) { + log.warn("Couldn't find bridge method to detect generic type bound for " + klass.getName() + "::convertToEntityAttribute"); + return (Class) candidate.getReturnType(); + } throw new IllegalArgumentException(); }