【发布时间】:2018-02-14 01:56:57
【问题描述】:
我正在使用spring-boot 1.5.6 RELEASE。我想做一件基本的事情,将我的查询从存储库中的 @Query 注释移动到任何 xml 文件。
经过一番阅读,我发现我们可以使用orm.xml 或jpa-named-queries.properties 来编写我的自定义查询。
我不了解这些 XML 文件必须存在的位置的文件结构。而且我的项目中没有META-INF 文件夹。
例子:
POJO 类:
@Entity
public Class Customer {
private int id;
private String name;
// getters and setters
}
存储库:
public interface CustomerRepository extends PagingAndSortingRepository<Customer,Integer> {
// this query I need from an external xml file as it might be quite complex in terms of joins
@Query("Select cust from Customers cust")
public List<Customer> findAllCustomers();
}
编辑:参考this stackoverflow question。我需要知道这些文件(orm.xml 和 persistence.xml)需要存储在哪里,因为我没有 META-INF 文件夹。
提前致谢!!
【问题讨论】:
-
是的,我遇到过这个问题。但是就像我提到的,我没有
META-INF文件夹,我很困惑这些properties/ xml文件必须存储在哪里。 @托德 -
请查看github.com/eclipse/examples/tree/master/jpa/employee.dynamic/… 和webdev.jhuep.com/~jcs/ejava-javaee/coursedocs/605-784-site/docs/… 的github 示例,如果META-INF 不存在,那么您必须创建它。
标签: java xml spring spring-boot spring-data-jpa