• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a way to retrieve a list of named parameters from a namedQuery?

 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried to search the JavaDocs of the Persistence API but couldn't found a interface for getting the names of the used parameters within a namedQuery. I use named parameters instead of a positional parameters which is in my opinion a better way, because you could easier find bugs.

I would like to have a list so I can check if all parameters are provided and if not to give them a default value. Now I will solve this by creating a separate method which is responsible for executing the query.getResultList() in this method I can hardcode this check, but this doesn't feel nice. So I prefer to develop a general method which does this.

 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've already designed a kind of solution in which a helper class will create a JPA-Query by using annotations and the java reflection. After a second thought i believe i want to use the named queries not in a way it supposed to be.

With this helper class I will keep al the JPA logic for selecting central in one class.

Thanks for your attention.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!