For simple named queries, generate “repository” methods.
E.g.
{code:java}@NamedQuery( name = "persons_by_city", query = "from Person where city = :theCity" ... ) @Entity class Person { ... @Basic String city; }{code}
leads to
{code:java}@Generated class Person_ { ...
public static List<Person> getPersonsByCity(String city, Session session) { ... } }{code}
An alternative would be to instead generate a distinct repository class which might be better given that:
# Hibernate named-queries can be defined at the package level # JPA static metamodel generation effective has to be done from an annotation processor; I’m not sure how feasible it is to do this from an annotation processor. We need to be able to parse the query (into SQM most likely) for semantic information. Again, not sure how feasible it is to do this from an annotation processor. |
|