• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java @Query annotation

 
Ranch Hand
Posts: 230
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Team,

I am new to Spring @Query framework hence I would like to understand the following scenario :-




I would like to understand how will it work if the @Query is commented and it looks as below :-



Please provide your comments.






 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring Data creates the JQL from the method name. Additional documentation here http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
 
Santosh Kumar Nayak
Ranch Hand
Posts: 230
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jayesh,

I wanted to understand when the "@Query" is commented (//@Query) then does Spring take care of the internal implementation ?

What is the exact syntax :-
@Query OR
//@Query

 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In all cases, Spring generates the class that provides the implementation of the method. When you provide a query in the Query annotation, the method generated by spring will use the query specified in your Query annotation. When you do not provide a Query annotation, Spring will create a JQL queryby parsing the method name. For example, findByEmailAddress will be converted to Select u for User u where emailAddress= ?
 
Santosh Kumar Nayak
Ranch Hand
Posts: 230
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do Spring @Query annotation support nested Queries ?
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Query annotation supports JQL queries and native SQL queries. It uses your underlying JPA provider which in turn runs JDBC queries against the database. So, the kind of queries that you can run will be limited to the JPA provider and the database. If the database doesn't support nested queries then Spring Data won't support nested queries

Look at the documentation of the JPA provider and database to figure out if nested queries are supported.
 
Santosh Kumar Nayak
Ranch Hand
Posts: 230
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the position for ?1, ?2 or ?3 needs to be followed in sequence ?

Would the below following convention work ?


@Query("SELECT * FROM (SELECT * FROM (SELECT * FROM table_name WHERE date between ?2 and ?3 AND name = ?1) A ) WHERE index between ?4 and ?5)")
 
A feeble attempt to tell you about our stuff that makes us money
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic