Set < AttributeDescriptor > mappedAttributes ( EntityDescriptor entity , AttributeDescriptor attribute , EntityDescriptor referenced ) { String mappedBy = attribute . mappedBy ( ) ; if ( Names . isEmpty ( mappedBy ) ) { return referenced . attributes ( ) . stream ( ) . filter ( other -> other . cardinality ( ) != null ) . filter ( other -> referencingEntity ( other ) . isPresent ( ) ) . filter ( other -> referencingEntity ( other ) . orElseThrow ( IllegalStateException :: new ) == entity ) . collect ( Collectors . toSet ( ) ) ; } else { return referenced . attributes ( ) . stream ( ) . filter ( other -> other . name ( ) . equals ( mappedBy ) ) . collect ( Collectors . toSet ( ) ) ; } }
Given an association in an entity find the attributes it maps onto in the referenced entity .