on 04-07-2006 7:15 AM
If i'm going to let the user search the database table (eg. Employee) based on 4 parameters, ie. employee id, employee name, position and address. In cmp entity bean, the stupid way is to create (2 power of 4) findByMethod ejb-ql statements to fulfill the search. Is there any dynamic way to do the querying of table for cmp bean with only one findByMethod?
Any suggestions or help would be much appreciated. Thanks.
If all the fields are available in your entity bean you can create an oql findbyMethod() and place 4 parameters in your search.
regards,
Dion
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dionisios,
I believe u meant the findByMethod is something like this:
select object(b) from MyEntity b where b.EMPID like ?1 and b.EMPNAME like ?2 and b.POSITION like ?3 and b.ADDRESS like ?4
but what if the user choose to either find by one, two or three parameters, how can at the runtime use the findByMethod which require 4 parameters ?
Hi Julius,
CMP unfortunately does not support dynamic OQL methods (unless something has changed since the last time I looked at the specs). There are however tools and software (eg powertier) that can provide this type of functionality (like a generic findBySQL(String sql) method) on some J2EE servers.
One way to solve it of course is to have 4 different methods, and then in your java code have a case or if statements selecting the correct one based on what the user enters. It is not a pretty solution but it would work.
regards,
Dion
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.