Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

 
Ranch Hand
Posts: 653
  • Mark post as helpful
  • send pies
  • 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: 22028
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic