I need to keep the all the named queries in a separate file. For example
@javax.persistence.NamedQueries({
@NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e")})
public class AllNamedQueries {
}
Now that much in itself causes an Error “Named queries can only be defined in Entity or MappedSuperClass class”.
How do I create Named Queries in a Separate file? By separate I mean files other than entity file.
You can use
orm.xmlthat allows you to define JPA mappings in XML. This approach is equivalent and overrides annotations.Example based on define named query in orm.xml with jpa and hibernate: