2016-11-19 5 views
2

JPA를 사용하여 OracleSQL 데이터베이스를 쿼리하고 있습니다. 는 그러나, 나는 오류를 얻고있다 : 나는 다음과 같은 쿼리를 작성하는 경우EntityManager 쿼리에서 속성을 확인할 수 없습니다.

String sqlQuery = "SELECT c FROM XD_FILES c WHERE c.CLIENT_ID = :clientId"; 
TypedQuery<File> query = em.createQuery(sqlQuery, File.class); 
query = query.setParameter("clientId", clientId); 
ArrayList<File> clientFiles = (ArrayList<File>) query.getResultList(); 

파일이 열이

Request processing failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: CLIENT_ID of: com.fdmgroup.pojo.File [SELECT c FROM com.fdmgroup.pojo.File c WHERE c.CLIENT_ID = :clientId] 

@ManyToOne(targetEntity = Client.class) 
@JoinColumn(name = "CLIENT_ID") 
private Client client; 

내가 확실하지 오전 이유가있는 것 같습니다로 "CLIEND_ID"에 링크 된 "client"필드.

+0

열 이름은 무엇입니까처럼해야 하는가? –

+1

"sqlQuery"는 SQL이지만 JPQL 용 API를 사용합니다! –

답변

1

쿼리에서 열 이름이 아니라 속성 이름을 언급해야합니다.

그래서 쿼리는 다음과 같아야합니다

String sqlQuery = "SELECT c FROM XD_FILES c WHERE c.clientId = :clientId"; 
1

귀하의 쿼리는 기본 쿼리를 보인다 아닌 JPQL, 당신은 두 가지 방법으로이 문제를 해결할 수 있습니다.

1) 변경 em.createQuery (sqlQuery, File.class); em.createNativeQuery (sqlQuery, File.class);

2) JPQL 네이티브 쿼리에서 쿼리를 변경, 쿼리는

select c from File c where c.client.clientID=:clientId 
(Assuming clientID is primary key column name in Client class)