Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic