liefke / org.fastnate

The Offline SQL Generator
Apache License 2.0
16 stars 11 forks source link

Support for globally defined AnyMetaDef #32

Closed liefke closed 6 years ago

liefke commented 6 years ago

When using Hibernates @Any annotation on a JPA property, Fastnate supports only @AnyMetaDef definitions attached to the field itself:

public class Entity extends BaseEntity {
    @Any
    @AnyMetaDef(idType = "long", metaType = "string", metaValues = {
        @MetaValue(targetEntity = ExampleEntity.class, value = "EE"), 
        @MetaValue(targetEntity = SecondEntity.class, value = "SE")
    })
    private BaseEntity anyEntity;
}

But Hibernate supports named @AnyMetaDefs at arbitrary positions for example:

@AnyMetaDef(name="anyMetaDefExample", idType = "long", metaType = "string", metaValues = {
    @MetaValue(targetEntity = ExampleEntity.class, value = "EE"), 
    @MetaValue(targetEntity = SecondEntity.class, value = "SE")
})
public class Entity extends BaseEntity {
    @Any(metaDef = "anyMetaDefExample")
    private BaseEntity anyEntity;
}

Fastnate should support these globally defined @AnyMetaDefs as well.

liefke commented 6 years ago

As Fastnate does not scan the whole classpath, it can't find every AnyMetaDef annotation. But it tries to find the named AnyMetaDef somewhere in the hierarchy of the current class or the hierarchy of the target type of the current attribute, which seems to cover most of the use cases of named AnyMetaDef annotations.

In addition this issue will fix the support for ManyToAny, which wasn't working before (never noted due to missing test cases).