2

I am using JPA to query an OracleSQL database. However, I am getting the error:

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]

When I write the following query

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

File has this column

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

I am unsure why as it appears to have the field "client" linked to "CLIEND_ID".

asd
  • 29
  • 2

2 Answers2

1

You will need to mention the property name in the query and not the column name.

So the query should look like the following:

String sqlQuery = "SELECT c FROM XD_FILES c WHERE c.clientId = :clientId";
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
1

Your query seems native query and not a JPQL, you can solve this in two ways.

1) change em.createQuery(sqlQuery, File.class); to em.createNativeQuery(sqlQuery, File.class);

2) Change your query from native query to JPQL, your query should be like

select c from File c where c.client.clientID=:clientId
(Assuming clientID is primary key column name in Client class)
Sreenath Reddy
  • 390
  • 8
  • 29