I think it's a general question because I'm not an expert. Like a lot of people, I've began to create my first queries by the classical way: select something on something where something = something lol.
Then, I've discovered Spring Boot with Hibernate and the repositories. Everything seems more simple with a getSomethingBySomething();
But now, I would like to find a way to transform some difficult queries into an hibernate/jpa dialect.
For example, it's easy to create a complicated request with tools like query builder (DB Forge or from another editor. Is there a way to obtain the same result but with Hibernate dialect instead of complicated SQL request with inner join and everything?
EDIT:
Here is an exemple of sql query I would like to transform in Hibernate dialect:
@Query(nativeQuery =true, value = "select s.* FROM doc_usecomp \n" +
" INNER JOIN document s \n" +
" ON doc_usecomp.doc_id = s.doc_id\n" +
" INNER JOIN user_company usercomp \n" +
" ON doc_usecomp.usercomp_id = usercomp.usercomp_id\n" +
" INNER JOIN company c on usercomp.usercomp_id = c.comp_id \n" +
"WHERE c.comp_city = 'PARIS'")
List<Document> findAllDocumentByMCity();
Seems very difficult to find the documents from all the companies from a city but I have the classical way to do it with sql but with hibernate...
Hope a solution exist!
Depends on your SQL. It's a good practice to use derived queries getSomethingBySomething() for 1-4 conditions. For more complex queries you can use JPA Criteria API spring-data-criteria-queries
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.