Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExtendedTypeFactory.visitDeclared throws IllegalArgumentException when generic type is an annotation type #153

eerichmond opened this issue May 24, 2012 · 1 comment


Copy link

@eerichmond eerichmond commented May 24, 2012

If an entity inherits from a generic object where T is NOT of type enum, class or interface it throws an IllegalArgumentException. I was wondering if we might be able to modify the com.mysema.query.apt.ExtendedTypeFactory class to allow annotations as a generic type T. The annotation is already a enum value in TypeElement but I'm not sure what would be involed in creating a "createAnnotationType()" method in ExtendedTypeFactory.


Below is an example of what I was trying to accomplish with the generic type. Unfortunately when I ran mvn generate-sources it threw an IllegalArgumentException.

public abstract class BaseObject<T extends Annotation> {
    private Class<T> getAnnotationType() {
        if (this.businessKeyType == null) {
            Type genericSuperclass = getClass().getGenericSuperclass();
            Class<?> superClass = getClass().getSuperclass();

            while(!superClass.equals(BaseObject.class)) {
                genericSuperclass = superClass.getGenericSuperclass();
                superClass = superClass.getSuperclass();

            ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
            this.businessKeyType = (Class<T>) parameterizedType.getActualTypeArguments()[0];

        return this.businessKeyType;

    public boolean equals() {
         List<AccessibleObject> businessKeys = new ArrayList<AccessibleObject>();

        for (Field field : clazz.getDeclaredFields()) {
            T businessKey = field.getAnnotation(getAnnotationType());
            if (businessKey != null) {


public class Person extends BaseObject<javax.persistence.Id> {
    private Long id;

public class Address extends BaseObject<javax.persistence.EmbeddedId> {
    private String street;
timowest added a commit that referenced this issue May 24, 2012
Copy link

@timowest timowest commented May 25, 2012

Released in 2.6.0

@timowest timowest closed this May 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants