2017-09-05 1 views
1

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(); 

} 

EDIT : this stackoverflow question 언급했다. META-INF 폴더가 없으므로이 파일 (orm.xmlpersistence.xml)을 저장할 위치를 알아야합니다.

미리 감사드립니다.

+0

[스프링 데이터 JPA에서 명명 된 쿼리에 XML 구성을 사용하는 방법] (https://stackoverflow.com/questions/24931248/how-to-use-xml-configuration-for-named-queries-in- spring-data-jpa) – Todd

+0

예, 저는이 질문을 접했습니다. 그러나 제가 언급했듯이,'META-INF' 폴더가 없으며,이'properties/xml' 파일을 어디에 저장해야하는지에 대해 매우 혼란 스럽습니다. @Todd – Anusha

+1

https://github.com/eclipse/examples/tree/master/jpa/employee.dynamic/src/main/resources/META-INF 및 http://webdev.jhuep.com/에서 github 예제를 확인하십시오. ~ jcs/ejava-javaee/coursedocs/605-784-site/docs/content/html/hibernate-migration-orm.html, META-INF가 없으면 작성해야합니다. –

답변

3

resources 폴더 안에 META-INF을 만듭니다. 이제 META-INF 폴더 안에 jpa-named-queries.properties 파일을 만듭니다.

이 속성은 다음과 같이 파일 내부에 조회를 작성 : 엔티티 클래스와 findAllCustomerByNamedQueryCustomer 나타낸다 이름은 고객 저장소에서 쿼리 이름

입니다

Customer.findAllCustomerByNamedQuery=Select c from Customer c

이 쿼리를 호출이 쓰기 속성 파일에 작성 :

List<Customer> findAllCustomerByNamedQuery();

+0

감사! 수동으로 META-INF를 만들면 나를 위해 일했습니다! application.properties와 같은 파일과 함께 생성되지 않는 이유가 있습니까? – Anusha

+0

그 이유를 모르겠다 –

+0

감사합니다! 정확히 무엇을 찾고 있었습니까. 이 정보는 어디에서 찾았습니까? –

관련 문제