Search in sources :

Example 16 with OneToMany

use of jakarta.persistence.OneToMany in project eclipselink by eclipse-ee4j.

the class AbstractMethodMapping method getMemberType.

@Override
protected Class<?> getMemberType() {
    Method method = getMember();
    Class<?> type = method.getReturnType();
    if (type == Void.class) {
        return method.getParameterTypes()[0];
    } else {
        // One to One
        OneToOne oneToOne = method.getAnnotation(OneToOne.class);
        if (oneToOne != null) {
            Class<?> targetEntity = oneToOne.targetEntity();
            if (targetEntity != void.class) {
                return targetEntity;
            }
        }
        // Many to One
        ManyToOne manyToOne = method.getAnnotation(ManyToOne.class);
        if (manyToOne != null) {
            Class<?> targetEntity = manyToOne.targetEntity();
            if (targetEntity != void.class) {
                return targetEntity;
            }
        }
        // Many to Many
        ManyToMany manyToMany = method.getAnnotation(ManyToMany.class);
        if (manyToMany != null) {
            Class<?> targetEntity = manyToMany.targetEntity();
            if (targetEntity != void.class) {
                return targetEntity;
            }
        }
        // One to Many
        OneToMany oneToMany = method.getAnnotation(OneToMany.class);
        if (oneToMany != null) {
            Class<?> targetEntity = oneToMany.targetEntity();
            if (targetEntity != void.class) {
                return targetEntity;
            }
        }
        return type;
    }
}
Also used : OneToOne(jakarta.persistence.OneToOne) ManyToMany(jakarta.persistence.ManyToMany) Method(java.lang.reflect.Method) OneToMany(jakarta.persistence.OneToMany) ManyToOne(jakarta.persistence.ManyToOne)

Aggregations

OneToMany (jakarta.persistence.OneToMany)16 ManyToMany (jakarta.persistence.ManyToMany)7 ElementCollection (jakarta.persistence.ElementCollection)5 Test (org.junit.Test)5 ManyToOne (jakarta.persistence.ManyToOne)4 OneToOne (jakarta.persistence.OneToOne)4 JoinColumn (jakarta.persistence.JoinColumn)3 JoinColumns (jakarta.persistence.JoinColumns)3 JoinTable (jakarta.persistence.JoinTable)2 MapKeyJoinColumn (jakarta.persistence.MapKeyJoinColumn)2 MapKeyJoinColumns (jakarta.persistence.MapKeyJoinColumns)2 OrderColumn (jakarta.persistence.OrderColumn)2 PrimaryKeyJoinColumn (jakarta.persistence.PrimaryKeyJoinColumn)2 PrimaryKeyJoinColumns (jakarta.persistence.PrimaryKeyJoinColumns)2 AnnotationException (org.hibernate.AnnotationException)2 AssertionFailure (org.hibernate.AssertionFailure)2 Columns (org.hibernate.annotations.Columns)2 Comment (org.hibernate.annotations.Comment)2 Formula (org.hibernate.annotations.Formula)2 LazyCollection (org.hibernate.annotations.LazyCollection)2