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

Support for globally defined AnyMetaDef #32

Closed
liefke opened this issue Apr 17, 2018 · 1 comment
Closed

Support for globally defined AnyMetaDef #32

liefke opened this issue Apr 17, 2018 · 1 comment
Assignees
Milestone

Comments

@liefke
Copy link
Owner

liefke commented Apr 17, 2018

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
Copy link
Owner Author

liefke commented Apr 18, 2018

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant