• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Confused over @Query, @Param etc and which library to use

 
Ranch Hand
Posts: 947
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to emulate the @Query function in this petclinic spring project :

https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java

Now, I realised that I can also extends JPARepository

And also at the annotation level I can or seems to be able or choose to use a variety of libraries from :



If I change all my queries to from javax.ws.rs ,will it cause any problem ?

Or is it safer to use @Param from org.springframework.data.repository.query.Param ?

I am really confused about this part..

Hope someone can advise me

Thanks.
 
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The three annotations have different purposes.

@QueryParam (javax.ws.rs) only works with JAX-RS. In other words, the web layer. It's meant to map a query parameter to a method argument. It cannot be used with Spring's @Query annotation.

@Param(org.springframework.data.repository.query.Param) is meant to be used in combination with @Query to define that a method argument should be mapped to a parameter inside the query. This is the one you need.

@Parameter(org.hibernate.annotation) is some Hibernate specific thing. No idea how it works, but it cannot be used with Spring's @Query annotation.
reply
    Bookmark Topic Watch Topic
  • New Topic