1

I have problem with my @Repository:

@Repository
public interface RekvZmRepository extends CrudRepository<RekvalZamestn, RekvalZamestnPk> {
@Query(value = "SELECT z.* FROM rek_zm d INNER JOIN proj_a a ON d.id = a.prj_idcislo"
  + "                                   INNER JOIN proj_e e ON a.id = e.id"
  + "                                   INNER JOIN rekv_z z ON d.id = z.id"
  + "WHERE  d.id = ?1 AND a.id = ?2 AND e.id = ?3", nativeQuery = true)
public List<RekvalZamestn> getRekvOsOnDoh(Long dhzmrk, Long prj, Long prje);
}

When I run it, result is:

org.springframework.dao.InvalidDataAccessResourceUsageException: could not
extract ResultSet; SQL [n/a]; nested exception is
org.hibernate.exception.SQLGrammarException: could not extract ResultSet

When I run SQL it works, so for me it looks like problem is not with SQL but with my @Query.

2 Answers 2

3

Your query, in one-line format (condensing multiple spaces to one space for reasons of, erm, space), equates to

SELECT z.* FROM rek_zm d INNER JOIN proj_a a ON d.id = a.prj_idcislo INNER JOIN proj_e e ON a.id = e.id INNER JOIN rekv_z z ON d.id = z.idWHERE  d.id = ?1 AND a.id = ?2 AND e.id = ?3

If you concatenate all the strings in one line like this, it becomes obvious that you are missing a space before the WHERE clause.

Sign up to request clarification or add additional context in comments.

Comments

0

change SELECT z.* FROM to SELECT z FROM assuming RekvalZamestn class maps to table rekv_z.

1 Comment

yes, RekvalZamestn maps to table rekv_z but it's native query. changing z.* to only z doesn't works (tested now).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.