Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 53 java ee 8 Heres how they work Behind the scenes an annotation class implementation must be marked with the @ Repeatable meta annotation to indicate that it can be utilized more than once The @ Repeatable meta annotation accepts the class type of the container annotation For example the NamedQuery annotation class is now marked with the @ Repeatable NamedQueries class annotation In this way the container annotation is still used but you do not have to think about it when using the same annotation on a declaration or class because @ Repeatable abstracts that detail away Heres an example If you wanted to add more than one @ NamedQuery annotation to an entity class in JPA 21 you had to encapsulate them inside the @ NamedQueries annotation as seen in Listing 4 Listing 4 @ Entity @ Table name CUSTOMER @ XmlRootElement @ NamedQueries @ NamedQuery name Customer findAll query SELECT c FROM Customer c @ NamedQuery name Customer findByCustomerId query SELECT c FROM Customer c WHERE c customerId customerId @ NamedQuery name Customer findByName query SELECT c FROM Customer c WHERE c name name public class Customer implements Serializable
You must have JavaScript enabled to view digital editions.