Search code examples
javametamodel

What is Metamodel API used for


I understand that metamodel is kind of an abstraction of entity classes, but what exactly it is and how can I profit from that?


Solution

  • They're used for writing Criteria queries for JPA.

    Also, it's used for writing Specifications (if you're using spring data)

    Specification<Foo> isBar() {
        return (root, query, builder) -> builder.isNotNull(root.get(Foo_.bar));
    }