aspose file tools*
The moose likes Object Relational Mapping and the fly likes How do I manuplate the named query at run time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How do I manuplate the named query at run time?" Watch "How do I manuplate the named query at run time?" New topic
Author

How do I manuplate the named query at run time?

Rahul bhirud
Greenhorn

Joined: May 15, 2007
Posts: 2
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29219
    
135

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rahul bhirud
Greenhorn

Joined: May 15, 2007
Posts: 2
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I manuplate the named query at run time?
 
Similar Threads
changing sql qery at run time on a jsp page using jstl
[JBoss 6.0 M1] EJB 3.0 Named queries (orm.xml)
Named queries and EJBQL
Unable to find database
Clarification regarding stored procedure Hibernate