dcsimg
dynamic queries in weblogic
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ronak_parekh
Posted On:   Saturday, February 22, 2003 02:29 PM

In case of dynamic queries, I found out that the finder method can not be defined in the Home class. I defined the finder method in the Bean. In my Bean, this is the code: public Collection findAllActivities(String filter, Object[] arguments) throws FinderException { Properties myProp = new Properties(); for(int i = 0; i < arguments.length; i++) { myProp.setProperty(String.valueOf(i), String.valueOf((arguments[i]))); } try { InitialContext ic = new InitialContext(); RolesHome rh = (RolesHome)ic.lookup("RolesHome"); Q   More>>

In case of dynamic queries, I found out that the finder method can not be defined in the Home class. I defined the finder



method in the Bean.



In my Bean, this is the code:



public Collection findAllActivities(String filter, Object[] arguments) throws FinderException

{

Properties myProp = new Properties();



for(int i = 0; i < arguments.length; i++)

{

myProp.setProperty(String.valueOf(i), String.valueOf((arguments[i])));

}



try

{

InitialContext ic = new InitialContext();


RolesHome rh = (RolesHome)ic.lookup("RolesHome");

QueryHome qh = (QueryHome)rh;



String weblogicQL = "SELECT DISTINCT OBJECT(o) FROM roles AS o" + filter;



Query query = qh.createQuery();



return query.find(weblogicQL, myProp);

}

catch (Exception e)

{

e.printStackTrace();

return null;

}

}



I get a naming exception if I use : RolesHome rh = (RolesHome)ic.lookup("RolesHome");



javax.naming.NameNotFoundException: Unable to resolve 'RolesHome' Resolved: '' Unresolved:'RolesHome' ; remaining name

'RolesHome'



I get a casting exception if I use: RolesHome rh = (RolesHome)ic.lookup("Roles");




In my jsp file:



I have this code



InitialContext jndiContext = new InitialContext();

Object obj = jndiContext.lookup("Roles");

RolesHome rolesHome = (RolesHome) obj;

list = (ArrayList) rolesHome.findAllActivities(filter, filterParams);



but the problem is that the home interface does not contain the findAllActivities function. I have already defined rolesHome



earlier in the code which I want to use for findAllActivities also. I can not cast the bean e.g. RolesBean rolesBean = (

RolesBean) rolesHome. I do not want to create a new bean as I am already using an old rolesHome. How do I solve this

problem??? Please do let me know. I am really confused.



Thanks

Ronak Parekh

   <<Less
About | Sitemap | Contact