• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I manuplate the named query at run time?

 
Rahul bhirud
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using EJB 3.0 entity beans and I have a specific requirement. I need to modify the named query at the run time like add some extra search criteria just before the actual execution. This needs to be done at the framework lavel so that developer do not care about it.

Can any body help?

Thanks in advance
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul,
Welcome to JavaRanch!

I don't think you can. A named query is constant. You can call entityManager.createNativeQuery().

If you know the changes at deploy time, you can create multiple named queries. If not, you need something more dynamic. If you expand on the requirement, we may be able to suggest other approaches.
 
Rahul bhirud
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne, thanks for the reply...

The requirement is simple. For each query being executed I want to put some restrictions depending upon the security constraints. For example in a accounting system, the logged in user has access to a set of departments, and this user should only see the Employees in that department. Now instead of putting department filter criteria in each query, I want to modify all the queries to add this criteria at the end(just before execution) depending upon the user access.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to move this to the ORM forum which will handle questions on EJB3 Entity Beans since it is now JPA and ORM based.

Thanks

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic