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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • 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 :

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 ,will it cause any problem ?

Or is it safer to use @Param from ?

I am really confused about this part..

Hope someone can advise me

Posts: 22028
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 ( 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( 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
    Bookmark Topic Watch Topic
  • New Topic