Toplink Named Query - Creating the Expression

In JDeveloper, I have this scenario.
I’ve created a:
Name.java – private String name;
Managed Bean – Name - id, Class - paperless.Name, Scope - session
Toplink Named Query --> findUserProfile
Type --> ReadObjectQuery
In the format tab, I’m using “Expression” and it is “1. pp_Username EQUAL “#{id.name}”
I’m trying to do a query on pp_Username where pp_Username equals the login name that I have stored in the session (id.name). I can only assume that I have my express written incorrectly. When I run it, I just get nothing. Any ideas?

Go to your toplink map in the application navigator, select the descriptor in the structure pane and then click on the "Queries" tab in the editor pane. You should be able to configure your named query there.
Hope this helps.
Anuj

Similar Messages

  • Adding "order by" functionality to the expression of a toplink named query

    hello,
    using JDev 10.1.3, I have made a Toplink named query findCustomersByCompany with a parameter company (String) to pass the name of the company of interest. I used the expression option from the format tab with"1.companyId LIKE IGNORE CASE company".
    The selection works fine but now I want the results to be ordered by customer name, the native order in the database is based on creation date.
    How can I add the order by clause to my named query using the expression format?
    kind regards,
    Nemata

    Look at http://www.thespot4oracle.com/SQL/re-6593_Adding-an-ordering-clause-using-a-TopLink-amendment-method.aspx
    Hope this helps.

  • TopLink named query issue

    We are using Jdeveloper 10.1.3.3, TopLink, ADF JSF Faces. I have an issue with TopLink named query. I am passing a value to parameter defined in the TopLink named query. The problem is that the parameter value is not being set when JSP page is loading for the first time and TopLink named query is not returning any results. When I click a button or refresh the page or some user action, then only the parameter value is set in the TopLink named query and returning the query results.Is this TopLink issue or is there any way to invoke action to fire the TopLink named query with the parameter value being passed at the time of loading JSP page ?
    Our project is held up due to this issue and I will highly appreciate if someone can help on this?
    Thanks in Advance.

    Go to your toplink map in the application navigator, select the descriptor in the structure pane and then click on the "Queries" tab in the editor pane. You should be able to configure your named query there.
    Hope this helps.
    Anuj

  • Named query creates wrong cast: CAST (? AS VARCHAR(32672))

    Hello!
    I'am working with Toplink on DB2 - which works great, so far - but now I face the following problem:
    A named query produces the following sql-code:
    ... WHERE (SAMPLEFIELDNAME = CAST (? AS VARCHAR(32672) ))
    The problem ist the cast: the data-base-fieldtype is a VARCHAR(255) so get an SQL-Exception. I can't change the database-schema, because this is legacy-stuff. I tried a lot (columnDefinition and length in @Column-annotation seem to be ignored at all) - but nothing worked.
    Thank you!
    Siegfried

    Hi,
    The DB2 Platform hard coded the casting of Strings to VARCHAR(32672) in the oracle.toplink.platform.database.DB2Platform class' writeParameterMarker method. So if the type is set to a String class on the argument, it will always be cast to VARCHAR(32672). You will need to override the writeParameterMarker method on a custom platform (extending DB2Platform) in such a way that if a string is given, VARCHAR(255) is used instead. That is, assuming all your strings are of size 255.
    Best Regards,
    Chris

  • Native TopLink named query with named parameters

    Hello,
    Defining my metadata in native TopLink xml and using the native TopLink's Session interface I can access and successfully execute a named query using positional parameters (parameters passed to match the ?1 ?2 etc). I used for this the Session.executeQuery(String, Class, List) method e.g.
    select p from Person p where p.name = ?1
    Now, how can I get the same Session to execute named queries using named parameters? None of the Session.executeQuery methods seem suitable ... Am I missing anything here? e.g.
    select p from Person p where p.age = :age
    I can't find in Session http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/b13698/oracle/toplink/sessions/Session.html a good match for this use-case. I would expect something like:
    Session.executeQuery(String queryName, Class target, List argNames, List argValues)
    or
    Session.executeQuery(String queryName, Class target, Map argsKeyedByName)
    but can't find any good match, can anyone please enlighten me?
    Thanks in advance,
    Best regards,
    Giovanni

    Hello Chris,
    Many thanks for your response. I am sorry if I did not explain my problem properly.
    Suppose I already defined a named query in the metadata XXXProject.xml using the <opm:querying ... this JPQL named query "customFinder" already exists and would look something like:
    select p from Person p where p.firstname=:firstname and p.lastname=:lastname and p.birthdate=:birthdate
    now say you want to execute this query from the Session:
    Vector args = new Vector();
    // how do you know the order? you shouldn't know the order!
    // you know only the parameter names and that's what I mean
    // about named parameters
    // This args setup is wrong ... I need a way to specify to which
    // parameter name each argument corresponds to. In other words
    // if the named query where criteria order of parameters is modified
    // perhaps because of pruning composite keys etc you won't break the
    // existing code ...
    args.add(new Date());
    args.add("Azua");
    args.add("Giovanni");
    Session session = ...
    session.executeQuery("customFinder", Person.class, args);
    JPA supports both type of queries positional parameters and named parameters. Your explanation above is only for the first, my question refers to the later.
    I have not yet found the api for this ... though I am investigating along the lines of:
    Query query = session.getQuery("customFinder");
    and then try to assign the arguments in the same order that the parameters are defined in query or?
    Thanks in advance,
    Best regards,
    Giovanni
    Edited by: bravegag on 29.05.2009 08:06

  • Toplink named query returns maximum 1413 results

    Hi all.
    As the heading states, I have a Toplink named query that returns 1413 results when it should return 3030. Is this configured somewhere? thanks in advance.

    Go to your toplink map in the application navigator, select the descriptor in the structure pane and then click on the "Queries" tab in the editor pane. You should be able to configure your named query there.
    Hope this helps.
    Anuj

  • Toplink named query and firstrow

    In one of our projects we have a need to chunk records returned by a Toplink query.
    For example if a query retrieves 1000 rows we need to chunk records in batches of a variable number.
    Lets assume for this one request we need to chunk these 1000 rows in batches of 50 records. Is there a way to do this with Toplink?
    I tried to create a named query and then am setting the first row to 0 and max rows to 20
    And in a loop I am adding 20 to the value of the first row.
    This does not work. The first time the query runs the first row = 0 and the max rows = 20 and I get 20 records back as I expected, but the next time the query runs after I change the value of firstrows to 21 and I do not get any records back even though the DB has a 1000 records.
    Is it possible to do this sort of batching of the result set? I appreciate any pointers on how to solve this
    Thanks a lot for the help

    Hello,
    MaxRows is independent of firstResult in TopLink; unless using a database that supports pagination, MaxRows is applied to the statement, and then firstresults used on the returned resultset to skip to the desired first row. So, the driver would return 20 rows, and then firstResult skips to row 20 - so nothing gets returned.
    MaxRows and FirstResult are used in TopLink as the range you want to be returned. So both need to be incremented so that the difference between them is the max number of rows you want returned - MaxRows could be better described as a LastResult instead.
    Best Regards,
    Chris

  • Clone of TopLink named query

    One of our projects here has a requirement where they'd like to modify, at runtime, the named query defined in the Mapping Workbench.
    One example is to set the refresh depth level (cascadePrivateParts, cascadeAll, for example) for the named query so that the defined query could be used in different scenarios with slightly different query options to get different query results.
    To support this, we will need to clone the query. See the sample code below:
    ObjectLevelReadQuery toplinkQuery = null;
    ObjectLevelReadQuery queryClone = null;
    Descriptor descriptor = session.getDescriptor(targetClass);
    DescriptorQueryManager queryManager = descriptor.getQueryManager();
    toplinkQuery = (ObjectLevelReadQuery)queryManager.getQuery(queryName);
    queryClone = (ObjectLevelReadQuery)toplinkQuery.clone();
    We try to use the clone method in DatabaseQuery. It seems to be working fine from the unit testing.
    Could someone provide me some information regarding the overhead (performance penalty) the clone method introduces?
    Thanks.
    Haiwei

    James,
    Thanks very much for your quick response.
    "The difference between using the clone vs not using the clone, is that clone (and changing the query) will trigger the query to no longer be prepared. This means that the query will need to re-generate the SQL for every execution."
    Is this always true or it depends on what query options got changed?
    I tried the cloneQuery with cloneQuery.cascadePrivateParts(). It seems that (from the trace) it still uses the prepared SQL. Here is the trace:
    in testQuery .....
    [3/8/05 15:27:47:027 EST] d510d51 SystemOut O 2005.03.08 03:27:47.027--ServerSession(1090797828)--Thread[Servlet.Engine.Transports : 1,5,main]--Connection(290525521)--SELECT * FROM QUOTE WHERE ID IN (?,?)
         bind =&gt; [1, 2]
    [3/8/05 15:27:47:037 EST] d510d51 SystemOut O 2005.03.08 03:27:47.037--ServerSession(1090797828)--Thread[Servlet.Engine.Transports : 1,5,main]--Connection(759639367)--SELECT NAME, ID, VERSION FROM USER04.SUBQUOTE WHERE (QUOTE_ID = ?)
         bind =&gt; [1]
    [3/8/05 15:27:47:037 EST] d510d51 SystemOut O 2005.03.08 03:27:47.037--ClientSession(219090191)--Thread[Servlet.Engine.Transports : 1,5,main]--client released
    A separate question, the cascade option is not configurable in the Mapping Workbench, is this something that TopLink deliberately does not provide?
    Thanks again for your assistance.

  • "where contains" in Toplink named query

    I´m using Toplink named queries to find documents in database. How can i use a parameter "keyword" inside an sql-statement? The statement looks like:
    select score(1), ID_DOCUMENTS_INDICATED, nvl(NAME,'--'), CREATE_DATE, LAST_UPDATE, USER_ID from IFCOB_DOCUMENTS_INDICATED where contains(BLOB_CONTENT, #keyword , 1) > 0;
    "keyword" is a String from an users input. I´m using JDeveloper 10.1.3 so there isn´t any TextWizzard for my jspx-application. Any solutions?
    Thx, Don

    Go to your toplink map in the application navigator, select the descriptor in the structure pane and then click on the "Queries" tab in the editor pane. You should be able to configure your named query there.
    Hope this helps.
    Anuj

  • TopLink doesn't sort data received using Named query

    Hello!
    I'm trying to build a Tree table using a TopLink Named query in my application.
    There are Id, Parent|_Id, Code and Name columns in the corresponding database table, where Id and Parent|_Id are linked together by Foreign key (typical tree). I used TopLink to describe this table in the Model part of my application. There I wrote a Named query, without using a query constructor (not Expression radio button, but SQL radio button). Here the text of query:
    select * from regions a connect by prior a.Id = a.Parent_Id start
    with a.Id is null order by a.Code
    Then I created a Data control and tried to build a JSF page with data based on this query, as tree-table.
    But I discovered the fact, that data under the same node on the same leaf level of the Tree are not sorted by code on the JSF page. For example, data may be situated as follows (Code - Name):
    2. wwwwwwwwwwww
    2.3.kkkkkkkkkkkk
    2.1.fffffffffffffffffffff
    2.2.oooooooooo
    1. qqqqqqqqqqqqqqqq
    1. 2. lllllllllllllllllllllllllllll
    1. 1. hhhhhhhhhhhhhh
    etc.
    I verified this query on other environment (PL/SQL Developer, SQL+), but didn't found such unsorted results anywhere.
    Please, give me an advice to avoid this problem.
    Thanks.

    Hi
    Something to do with TreeMap(TreeSet). I tried with TreeSet but it didn't work. Here is the code :
    In servlet :
    Connection lConnection = getConnection(pRequest);
    String lSQL = "";
    Statement lStatement;
    ResultSet lResultSet;
    Hashtable lLtypeHashtable = new Hashtable();
    lStatement = lConnection.createStatement();
    lSQL = "SELECT RCID,RCMEANING FROM REFERENCECODES WHERE RCDOMAIN = 'LOCATIONTYPE' AND RCROWSTATE > 0 order by RCMEANING";
    lResultSet = lStatement.executeQuery(lSQL);
    while(lResultSet.next())
    String lRcid = lResultSet.getString(1);
    String lRcmeaning = lResultSet.getString(2);
    lLtypeHashtable.put(lRcid.trim(),lRcmeaning.trim());
    if(lResultSet != null) lResultSet.close();
    if(lStatement != null) lStatement.close();
    pRequest.setAttribute("LtypeHashtable",lLtypeHashtable);
    //Below Query is executed when one data from select element is selected
    String lLType = DisplayUtilities.getString(pRequest.getParameter("LType"),true);
    //LType is name of select element in JSP.
    if (lLType != null)
    lSQL = lSQL + " AND " + lUpperCaseFunction + "(LOCATIONTYPE)" +
    " = " + DBUtilities.formatString(lLType.toUpperCase());
    pRequest.setAttribute("rLType",lLType+"");
    In JSp :
    <%
    Hashtable lLtypeHashtable = (Hashtable)request.getAttribute("LtypeHashtable");
    %>
    <TR>
    <TD width="15%"> <div align="left">
    <select name="LType" size="1" >
    <option Value="">< Select ></option>
    <%
    if(lLtypeHashtable != null)
    Enumeration enum = lLtypeHashtable.keys();
    while(enum.hasMoreElements())
    String key = (String)enum.nextElement();
    String value = (String)lLtypeHashtable.get(key);
    String flagBack = "";
    if(key.equals((String)request.getAttribute("rLType")))
    flagBack = "selected";
    %>
    <option Value="<%=key%>" <%=flagBack%>><%=value%></option>
    <%
    %>
    </select></div>
    </TD>
    </TR>
    How should I implement TreeSet?
    Looking forward for an early reply.
    Thanks.

  • Creating Named Query: from OracleCallableStatement

    We have a great many PL/SQL Procs in an existing legacy system that return PL/SQL Boolean, that we wish to call from toplink.
    Ideally we would like to create Toplink Nameded queries that wrap the SQL call statements.
    Does anyone know if its possible to convert a call like the following into a Toplink named query?
    String domain = "COST CENTRE";
    String value = "OP";
    OracleCallableStatement xcall = (OracleCallableStatement) con.prepareCall(
    "BEGIN ? := SYS.SQLJUTL.bool2int(is_valid_value(?, ?)); END;");
    xcall.registerOutParameter( 1, OracleTypes.INTEGER);
    xcall.setString(2,domain);
    xcall.setString(3,value);
    xcall.execute();
    System.out.println ("Status = " + xcall.getInt(1));
    FUNCTION is_valid_value(
    p_rv_domain IN CG_REF_CODES.RV_DOMAIN%TYPE,
    p_rv_low_value IN CG_REF_CODES.RV_LOW_VALUE%TYPE
    RETURN BOOLEAN
    IS
    Many thanks,
    Lee.

    You can define Stored Procedure calls in TopLink through the StoredProcedureCall class. StoredProcedureCall allows you to define output parameters to access return values.
    Example:
    StoredProcedureCall call = new StoredProcedureCall();
    call.setProcedureName("is_valid_value");
    call.addNamedArgumentValue("DOMAIN", domain);
    call.addNamedArgumentValue("VALUE", value);
    call.addNamedOutputArgument("RESULT", "RESULT", Integer.class);
    List results = session.executeSelectingCall(call);
    boolean value = ((Integer) ((Map) results.get(0)).get("RESULT")).intValue() == 0;
    However what you seem to be accessing is a stored function, not a procedure. To access a stored function from TopLink you must use an SQLCall and select the return value through the DUAL table.
    Example:
    SQLCall call = new SQLCall("Select SYS.SQLJUTL.bool2int(is_valid_value(" + domain + ", " + value + ")) from dual");
    List results = session.executeSelectingCall(call);

  • Questions on Named Query

    We have a few questions about named query.
    According to the Toplink documentation, we can register the named query in 2 places.
    1. Register the name query in the “query manager” in a Session level - The documentation said that these are for “GLOBAL” queries.
    2. Register the name query in the “query manager” in a Descriptor level. These “Descriptor level” query can be defined via the Toplink workbench or defind via Java code and load in the Descriptor via a post-project load amendment method. The documentation also mentioned that once the project is login, we cannot add named query to the descriptor.
    We have a few questions.
    All querys are related to a class, so what do we mean by “GLOBAL” queries ? What is this “GLOBAL” means.
    Is there any restriction in adding query to a session. Can we add query to a session after the session is login ?
    What we like to achieve is something like this.
    Ask the session for a query “findElectionByEmployee”, if nothing returns, construct the query, add this named query to the session.
    Can we ask a clientSession for a query using getQuery(string)?
    Or we can only ask a serverSession for a query ?
    How about adding query to a session, can a clientSession add a query back to the parent ServerSession, or we need to add the query directly to a serverSession ?
    We have hundreds of queries, not all of them used all the time, so adding the query to the session “on demand, or Just in Time addition”, will be most memory saving rather than starting the system with hundreds of query.
    Another issue we have about using descriptor based query, specially those that is define via the toplink workbench, is that it create sort of an administrative single point of entry. For a system that have a lot of query, to single file the creation of the query to a single person, or a few people, can be administratively difficult, even though we appreciate the “central and single point of control aspect of it.
    So what is your observation in the use of named queries with your other clients ?
    Is that a popular feature that your customer use ? Do they like to define the query in Workbench, can this solution “administratively scale” ?
    Do you see “just in time” add of query to a session, if that is all possible.
    Currently we have a simple query mechanism, each DAO method eg findElectionByEmployee, will contruct the query, with the expression builder, expressions etc and after one execution, throw that away and redo the same thing again in the next method invocation.
    We want to avoid that but we do not want to centralized the definition to a central “Toplink Mapping” person. For a fairlt big system like ours, that have 20-30 DAO with hundreds of “finder” methods, it is too difficult to centralized.
    What is your thoughts on this and if there is any white paper of best practice that you can point us to, we be most appreciated.

    In answer to your technical questions, the only difference between descriptor level named queries and session level named queries is where the query is stored. Queries stored at the session level must have unique signatures, queries stored in the descriptor require unique signatures from other queries on the same descriptor but not queries on other descriptors or sessions.
    Queries at the session level can be on any class, queries at the descriptor level must on that descriptor's class.
    A ServerSession's query can be found from a ClientSession but queries added to a ClientSession will only be available to that ClientSession and will dispose when the ClientSession is released.
    As to the questions about manageability it really is up to you to evaluate. If it is important to your organization that queries are moderated centrally then controlling them at the project level would provide for that. If that is not an important requirement then moving to a dynamic model would be less overhead, and headaches of having numerous people working on the source to and redeploying the same application repeatedly. But in general a combination of the two approaches, based on how often a particular query is used, would probably be best.
    --Gordon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • IN operator in Named Query

    hi all,
    is it possible to create a named query containing the IN clause if yes how to pass the parameters , i have smth like that:
    "select * from tblUsers where employee_number in #param"
    what should be the type of the parameter?

    You can create a named query using an IN parameter, but you should be careful in doing this as an IN collection is not a valid parameter in SQL. TopLink will handle translating the IN as long as you are using dynamic SQL, or disable the prepare on the query. You can use Vector as the parameter value.
    i.e.
    ReadAllQuery query = new ReadAllQuery(Employee.class);
    query.setSQLString("select * from tblUsers where employee_number in #param");
    // Or: query.setSelectionCriteria(query.getExpressionBuilder().get("number").in(query.getExpressionBuilder().getParameter("param")));
    query.setShouldPrepare(false);
    query.addArgument("param");
    Vector args = new Vector();
    Vector param = new Vector();
    param.add(new Integer(1));
    param.add(new Integer(2));
    param.add(new Integer(3));
    args.add(param);
    session.executeQuery(query, args);
    // Or: session.executeQuery("findAllWithNumbers", Employee.class, args);

  • Named query question

    Hi Guys,
    I have the following problem - I know I did something wrong, but I cannot figure out how to correct it. Here is my question:
    I have a table tableA, with composite key (col1, col2, col3, col4). I mapped the table, and create a Toplink named query (findCol3List)as such:
    select distinct col3
    from tableA
    where col1=#col1 and col2=#col2
    I created an EJB session method getCol3List(col1, col2) -
    now when I run the application to call this EJB method, I got the following error at line:
    List results = (List)session.executeQuery("findCol3List", String.class, params);
    Exception Description: Missing descriptor for [java.lang.String] for query named [findCol3List].
    I know there are multiple mistakes in my approach, but with my limited Toklink knowledge, I could not figure out.
    Any help with be appreciated!

    hello,
    The executeQuery method is trying to look up the "findCol3List" in the descriptor for the class passed in. It is complaining because you passed in String.class which does not have a valid descriptor.
    How/where did you define the named query? Chances are you defined it in the class used for TableA, and so should specify it in the executeQuery method:
    session.executeQuery("findCol3List", tableA.class, params);
    Best Regards,
    Chris

  • Need help with named query for 1-to-many entities

    Hi all,
    I'm in desperate need of a query and I can't seem to figure it out.
    Here's the situation:
    I have 2 entities in a one-to-many relationship. One ServerInstance to Many AppUrl's related by a join table
    @Entity
    public class ServerInstance implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer id;
    private String instancename;
    private String description;
    private String home;
    private String hostname;
    private String hostname_front;
    private String ipfront;
    private String ipback;
    private String os;
    private String layer;
    @OneToMany (fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
    private List<AppUrl> appUrl = new ArrayList<AppUrl>();
    @Entity
    public class AppUrl implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer id;
    private String appurl;
    private String description;
    private String keyword;
    private Integer priority;
    private String curlresult;
    In the underlying database they are mapped by the table T_SERVERINSTANCE_T_APPURL
    What I need is a named query in the ServerInstance entity to find any AppUrl where curlresult = 'down'
    I tried the following:
    @NamedQuery
    (name = "findDownInstances", query = "SELECT i FROM ServerInstance i WHERE i.appUrl.result = 'down')
    This gave me the following error:
    invalid navigation expression [i.appUrl.result], cannot navigate collection valued association field [appUrl].
    Is there any way to create a query which will do what I want?
    Thanx in advance!

    can you provide the equivalent SQL (not JPQL!) query that you want, based on tables T_SERVERINSTANCE and T_APPURL, so that there are no misunderstandings ?

Maybe you are looking for

  • Huey Pro not working after Windows 7 Ultimate install on W510

    I just received my W510 and installed Windows 7 Ultimate x64 as well as all of the relevant W510 drivers. I've also installed Huey Pro. I've read many similar posts regarding the Huey Pro issue and followed all of them. Unfortunately Huey Pro isn't a

  • CrystalReportViewer in WPF - win32 exception on application closing

    Hello! I'am using the CrystalReportViewer Control in a WindowsFormsHost control as the rest of the application is made in WPF. If the application is closed when a Report is open, the "Visual Studio JIT" Debugger windows is opened informing me that an

  • NEED HELP BUYING NEW TV

    OK GOING TODAY TO BEST BUY FOR A TV! AFTER DAYS AND NIGHTS  OF ON THE INTERNET IV COME UP WITH LG  47 LE8500 (LED) now i find its only in warehouse UMM! !! I NEED TO KNOW IF ANYONE WAS TO BUY A 47 INCH TV ANY ONE YOU WANT (MUST BE 46,47 INCH) what on

  • Strange Error when pass variable to PHP

    I am passing the following variable from java to a php variable but I am getting an extra character. For example: char c= ' " '; String s1 = "Hello World"; String s2 = c+s1+c;When I pass s2 to a php varibale using URLEncoder.encode(s2) php prints out

  • Adobe flash CS3 professional trial version installation problem

    hi, I am trying to install the adobe flash CS3 professional trial version on windows installed and it complains that "internet explorer" is opened. I killed all the processes "iexplore.exe" , it still complains the same thing. Please let me know...am