dynamic queries in weblogic

Discussions

EJB programming & troubleshooting: dynamic queries in weblogic

  1. dynamic queries in weblogic (1 messages)

    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
  2. dynamic queries in weblogic[ Go to top ]

    Please make Role Ejb in your ejb-jar.xml as ejb-ref. Then you can get the environment and call the internal EJB through initial context Otherwise you have to pass the parameters url and contextfactor class to initial context.