Named Native Query Problem

I am running JDev 11g patch 2 (11...3) on a windows 7 machine. JDK 1.6_18
@NamedNativeQueries({
@NamedNativeQuery(name = "MenuFolders.findFolderByUser",
query = "SELECT * FROM menu_folders where mf_id is null and id in (select mf_id from userfoldervw where UPPER(user_name) = :p_user) order by display_order",
resultClass = MenuFolders.class)
I have entered the above code in to a entity bean - but all I get back when I run is invalid SQL statement - it works fine in a sql window.
I tried to use just "SELECT * FROM menu_folders " and get the same problem. Many of the examples show the same format as in the namedQuery ("select o from menuFolders o") but I thought the principle of native querys was to use standard SQL - just for this reason - not everything can be done in sql expression language.
Two things 1) mf_id is self referencing and there is no definition for the column in the regular EJB code. 2) userfoldervw is outside the bean (and yes it is a view)
There is a secondary issue - this is a master for another table which holds the actual items (forms).
I want to build a menu tree - normally I would do this in a backing bean and problematically build the tree menu - however - with JDeveloper this does not appear to be an option.
I have the system working fine in the Netbeans IDE using the backing bean.
I was looking for the adfMenuTree (the adfTree does not have the folder/node concept. I cannot find sufficient info on the adfTree to understand how it manages levels to make any sense out of it.)
Can someone give me a hand on this (either a backing bean solution with the adfTree or a view object - or just the sql)?

I have been developing with NetBeans and find it a much simpler IDE to work with but it is not time to move on.
The project I have been working on has a basic splash screen -> Login -> Menu structure.
The menu is based on a workflow and role concept. In the login I capture the users roles and the location code. These are stored in a session bean.
The username and the location code then govern the items in the menu and a to do list that is in a split panel (menu on left and to dos on the right with a button that takes them to the appropriate page based on workflow)
The issue I had with ADF was the lack of a data control in the page - I was using pure JSF. When I looked at the backing bean in the debugger - the input text was not being passed to the backing bean.
I was able to solve this by a bit of editing in the jsp and some movement in the locations. What I found interesting was that the methods in the backing bean worked fine (with the NPE due to the lack of the binding of the input text to the backing bean).
I am trying to move my skills into ADF/JDeveloper - and finding that it is a very obtuse IDE. The focus seems to be on technology rather than application development.
I came from the Oracle Forms/Reports environment and used the Designer2000 extensively - the focus was only on the business logic - the rest was generated for you.
With NetBeans - I found a similar focus. JDeveloper however is a different animal - I have spent hours and read tons of material - and still cannot find answers to very simple things.
I have a good example - I have a view object that takes a parameter - it looks to me like I will have to write over 100 lines of code to get this to work and I an still not sure how I will manage it in a backing bean.
I have no control - other than a button to execute a method (Netbeans had an abstract page bean that exposed parts of the life cycle (init, prerender, etc ...) that allowed me to execute code at specific life cycle stages - I have not found anything at all in the ADF that would guide me in doing the same.
According to all the documentation I have read (considerable) I will have to defeat ADF and do everything programatically - what a waste of good technology and my time.
I may be wrong - I hope I am - maybe some one can point me into a direction that can help me with this (everything in the tutorials misses these simple issues that we use every day).

Similar Messages

  • NAMED SQL QUERY PROBLEM

    I am trying to run a named read all query, which requires me to use the "AS" keyword for tables to eliminate ambiguity. This does not appear to populate my vector of object, as I assume the field names end up being different ie. FIELD1 gets T.FIELD1.
    Any help with this will be greatly appreciated
    Here is my query:
    SELECT L.VLN_LAST_VLE_SQID, L.REC_CHANGE_DATE, L.VLN_LENDER_OE,
    L.REC_CHANGE_USER, L.VLN_LG_LN_NUM, L.REC_CREATE_TIME, L.VLN_LG_LN_NUM_SEQ,
    L.REC_PROGRAM, L.VLN_LG_STATUS, L.SYN_SYNC_SGT_KEY, L.VLN_LOAN_AMOUNT_ADJ,
    L.SYN_SYNC_STAT_IN, L.VLN_LOAN_TYPE, L.VLN_ACADEMIC_YEAR, L.VLN_LOAN_TYPE_REQ,
    L.VLN_ANTICIPATED_GRAD_DATE, L.VLN_NON_ED_BRNCH, L.VLN_APP_SOURCE,
    L.VLN_NOT_USED_STAT_1, L.VLN_BORROWER_ID, L.VLN_NOT_USED_STAT_2,
    L.VLN_CAPPED_INTEREST, L.VLN_NSLDS_EFFECTIVE_DATE, L.VLN_CERT_ENR_STATUS,
    L.VLN_NSLDS_ID, L.VLN_CL_UNIQUE_ID, L.VLN_NSLDS_LAST_VALUE,
    L.VLN_CONVERTED_DATE, L.VLN_NSLDS_SEPARATE_LOAN, L.VLN_COSIGNER_ID,
    L.VLN_NSLDS_STATUS, L.VLN_CREDIT_CHECK_DATE, L.VLN_NSLDS_UPDATED_DATE,
    L.VLN_CURRENT_PRINCIPAL, L.VLN_ORIG_LENDER_OE, L.VLN_DEFERMENT_REQUESTED,
    L.VLN_OTHER_DEBT, L.VLN_DISB_METHOD_REQUESTED, L.VLN_PAYOFF_AMOUNT,
    L.VLN_END_DATE, L.VLN_PIF_DATE, L.VLN_FAMILY_CONTRIBUTION,
    L.VLN_PIF_PAYMENT_REC_DATE, L.VLN_FISCAL_YEAR, L.VLN_PIF_PRIN_AMT_DISB,
    L.VLN_GALAHAD_STAT, L.VLN_PLUS_STATUS, L.VLN_GH_LOAN_SEQ,
    L.VLN_PN_SIGNATURE_DATE, L.VLN_GUARANTOR, L.VLN_PRE_DISB_CANC_AMOUNT, L.VLN_ID,
    L.VLN_PREV_DEFAULT, L.VLN_INT_ELIGIBILITY, L.VLN_PRIOR_ORIG_2ND_INT_RT,
    L.VLN_INTERIM_MATURITY_DATE, L.VLN_PRIOR_ORIG_EXIT_DATE,
    L.VLN_INTERIM_PAYMENT_DATE, L.VLN_PRIOR_ORIG_INT_RATE,
    L.VLN_INT_RATE_CATEGORY,
    L.VLN_PROMISSORY_NOTE, L.REC_CHANGE_TIME, L.VLN_PROM_NOTE_TYPE,
    L.REC_CREATE_USER, L.VLN_REMAINING_NEED, L.SYN_SYNC_SOURCE,
    L.VLN_REPORT_FFELP_LOAN, L.VLN_ADS_STATUS, L.VLN_REQ_AMT, L.VLN_BLAA,
    L.VLN_RESEARCH, L.VLN_CERT_AMT, L.VLN_SALE_DATE, L.VLN_CONS_SUBSIDY,
    L.VLN_SCHOOL_CERT_DATE, L.VLN_COST_OF_EDUCATION, L.VLN_SCHOOL_OE,
    L.VLN_CUST_SERVICE, L.VLN_SCHOOL_REF_AMT, L.VLN_DISB_SUMMARY,
    L.VLN_SCHOOL_REF_DTE, L.VLN_FINANCIAL_AID, L.VLN_SEPARATION_DATE,
    L.VLN_GH_CLAIM_NUM, L.VLN_SERIAL_P_N, L.VLN_GUAR_DATE, L.VLN_SLAA,
    L.VLN_INTEREST_RATE, L.VLN_SLSS_GR_ID, L.VLN_INTERIM_PMT_REC_DATE,
    L.VLN_SLSS_LENDER_ID, L.REC_CREATE_DATE, L.VLN_SLSS_LG_LN_NUM,
    L.SYN_SYNC_STAT_OUT, L.VLN_SLSS_LN_NUM, L.VLN_CANC_DATE, L.VLN_SLSS_STATUS,
    L.VLN_CONVERTED_PRIN_AMOUNT, L.VLN_SPEC_PROGRAM, L.VLN_DENIED_DATE,
    L.VLN_START_DATE, L.VLN_GALAHAD_LOAN_TYPE, L.VLN_STATUS, L.VLN_INCREASED_UNSUB,
    L.VLN_STATUS_IN_SLSS, L.VLN_INT_RATE_TYPE, L.VLN_STUDENT_ID, L.VLN_APP_DATE,
    L.VLN_SUB_UNSUB_SWAP, L.VLN_CURRENT_INTEREST, L.VLN_VERMONT_RELATIONSHIP,
    L.VLN_GUAR_AMT, L.VSAG_AID_GROUP, L.REC_STATUS, L.VSIB_BRANCH_ID,
    L.VLN_EXIT_ENR_STATUS, L.VSIN_ID, L.VLN_CLAIM_ASSIST_STATUS, L.VSLR_CODE,
    L.VLN_INTERIM_PAID_AMOUNT, L.VSLS_STATUS FROM COMMONDTA.VSLN00P AS L,
    COMMONDTA.VSPR00p AS P INNER JOIN COMMONDTA.VSAT00P AS A ON
    L.VLN_LOAN_TYPE=A.VSAT_AID_TYPE AND A.VSAT_CONSOL_LOAN='Y' WHERE
    L.VLN_BORROWER_ID = 177973 and L.VLN_CURRENT_PRINCIPAL > 0.0 AND
    L.VLN_BORROWER_ID = P.VPR_PERSON_ID AND P.VPR_SSN__CHAR_ = '00XXXXXXX'

    Sorry for yelling in the subject. I accidentally pasted from a text file and forgot myself.
    Jason

  • Named Query or Native Query

    Hello,
    I am using native query to search for results on my search page. A friend of mine just told me that I better use named query or the time to get my search results will be too slow.
    Does Named Query give you faster result than Native Query?
    Thanks in advance.
    Regards,
    Hemen

    When you define named queries (note that this is a Hibernate example) you can put them in for example XML,
    <query name="findItemsByDescription">
    <![CDATA[from Item item where item.description like :desc]]>
    </query>or a SQL query like
    <sql-query name="findItemsByDescription">
    <return alias="item" class="Item"/>
    <![CDATA[select {item.*} from item where description like :desc]]>
    </sql-query>You can call these queries by using the same code, for example,
    session.getNamedQuery("findItemsByDescription").setString("desc", description);This is what is being meant by sharing the same calling API.
    When taking about performance. You have to know something about what goes on under the hood.
    You have probably programmed something using straightforward JDBC, so you know how to queries
    get passed to the driver and send to the database. When using HQL or JPA-QL the queries first have
    to be parsed into an SQL language that the database can understand. In this case, we have an extra
    parsing step in between. Note that Native SQL queries, including stored procedure calls, the persistence
    framework still takes care of mapping the JDBC result sets to graphs of persistent objects.
    If you want to include a native SQL hint to instruct the database management systems query optimizer,
    for example, you need to write the SQL yourself. HQL and JPA-QL do not have keywords for this.
    The disadvantage of putting native SQL in your mapping metadata is lost database portability, because
    your mappings, and hence your application, will work only for a particular database. But usually this is of a
    minor concern as you are probably not creating a framework that has to work on every database.
    When you want to get behind the performance of your query, you really have to consult the database
    and look at the execution plan - A DBA can tell you exactly what is good and what can be optimized.

  • Issue in running GTC having Customized & native query

    Hi Experts,
    We are creating "OIM 9.1 - OIM11g SYNC GTC". When Scheduled task is run, this GTC should be updating the records of OIM11g by taking the data from OIM 9.1 DB.
    We have used the following connection parameters:
    Specify Parameter Values Change
    Database Driver oracle.jdbc.driver.OracleDriver
    Database URL jdbc:oracle:thin:@***************:1521:oimusdb
    Database User ID oimdev
    Database Password ********
    Customized Query (USRIMPORT.USR_EMP_TYPE='Employee' or USRIMPORT.USR_EMP_TYPE='Contractor') and USRIMPORT.USR_STATUS<>'Deleted'
    Use Native Query Yes
    Connection Properties
    Parent Table/View Name USRIMPORT
    Child Table/View Names
    Unique Attribute USR_KEY
    Timestamp Attribute USR_CREATED
    Database Date format
    Batch Size All
    Stop Reconciliation Threshold None
    Stop Threshold Minimum Records None
    Source Date Format yyyy/MM/dd HH:mm:ss z
    Reconcile Deletion of Multivalued Attribute Data No
    Reconciliation Type Incremental
    While running the GTC we are getting following error in logs:
    [XELLERATE.GC.FRAMEWORKRECONCILIATION] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JIbnbxk7u1ADrb4ioY1F10jR000002,0] [APP: oim#11.1.1.3.0] Reconciliation Encountered error: [[
    com.thortech.xl.gc.exception.ProviderException: For non-native customized query, please use & for AND and | for OR.
    at com.thortech.xl.gc.impl.recon.DBReconTransportProvider.getCustomizedQueryCondition(Unknown Source)
    For resolving the above issue, we have tried following combinations: (WHICH ARE NOT WORKING TILL NOW)
    1. Scenario 1:
    query: (USRIMPORT.USR_EMP_TYPE='Employee' | USRIMPORT.USR_EMP_TYPE='Contractor') & (USRIMPORT.USR_STATUS='Disabled' | 'USRIMPORT.USR_STATUS='Active')
    USE NATIVE QUERY = 'NO'
    ERROR: [XELLERATE.GC.FRAMEWORKRECONCILIATION] [tid: OIMQuartzScheduler_Worker-4] [userId: oiminternal] [ecid: 0000JIbnbxk7u1ADrb4ioY1F10jR000002,0] [APP: oim#11.1.1.3.0] Reconciliation Encountered error: [[
    com.thortech.xl.gc.exception.ProviderException: For non-native customized query, please use & for AND and | for OR.
    at com.thortech.xl.gc.impl.recon.DBReconTransportProvider.getCustomizedQueryCondition(Unknown Source)
    2. Scenario 2:
    query- (USRIMPORT.USR_EMP_TYPE='Employee' OR USRIMPORT.USR_EMP_TYPE='Contractor') AND (USRIMPORT.USR_STATUS='Disabled' OR 'USRIMPORT.USR_STATUS='Active')
    USE NATIVE QUERY ='yes'
    ERROR:
    class/Method: DBFacade/getRecord encounter some problems: ORA-00920: invalid relational operator[[
    java.sql.SQLSyntaxErrorException: ORA-00920: invalid relational operator
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)
    3. Scenario 3:
    query- (USRIMPORT.USR_EMP_TYPE='Employee' OR USRIMPORT.USR_EMP_TYPE='Contractor') AND (USRIMPORT.USR_STATUS='Disabled' OR 'USRIMPORT.USR_STATUS='Active')
    USE NATIVE QUERY='NO'
    ERROR:
    ERROR] [] [XELLERATE.GC.FRAMEWORKRECONCILIATION] [tid: OIMQuartzScheduler_Worker-6] [userId: oiminternal] [ecid: 0000JIbnbxk7u1ADrb4ioY1F10jR000002,0] [APP: oim#11.1.1.3.0] Reconciliation Encountered error: [[
    com.thortech.xl.gc.exception.ProviderException: For non-native customized query, please use & for AND and | for OR.
    at com.thortech.xl.gc.impl.recon.DBReconTransportProvider.getCustomizedQueryCondition(Unknown Source)
    at com.thortech.xl.gc.impl.recon.DBReconTransportProvider.getQueryCondition(Unknown Source)
    at com.thortech.xl.gc.impl.recon.DBReconTransportProvider.getFirstPage(Unknown Source)
    Please guide me on the same.

    Hi,
    Thanks for this but i have done as per this document. while running i came to know that there are 2 executable programs in the same name. so i need to remove the one executable program then i run this concurrent program to confirm it. that really we achieved it or not.
    Awaiting for your reply
    Thanks
    M.K.Thamaraiselvan.

  • Incremental variable in column native query

    i'm looking for a jpql way of doing a cumulative variable query like subttl:
    select scat.*, @subttl:=if(@subttl=null,0,@subttl) +imp*dh as subttl from scat;is there any way to use variables in the select clause ?...
    As other way, I thought making a native query but I need the resultset mapped to an entity bean, so I think it can't be possible.
    I appreciate your help!!

    Hi sebatxtz!
    You can always use SqlResultSetMappings to map the result of a native query to entities.
    [http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SqlResultSetMapping|http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#SqlResultSetMapping]
    As for your original problem, sorry I'm not that big of a jpql expert. :(
    -Zsom-

  • Confusion over Native Query Result List

    I have this confusion over the field object of a resultList of a Native query. This is because it has contradicted the idea of the books for me.
    This is a pure example
    @SqlResultSetMapping(name="LoanCapitalization.reportMapping",
    columns={
        @ColumnResult(name="policy_number"),
        @ColumnResult(name="policy_holder"),
        @ColumnResult(name="amount"),
        @ColumnResult(name="outstanding_loan"),
        @ColumnResult(name="interest"),
        @ColumnResult(name="amount_to_date"),
        @ColumnResult(name="effective_date"),
        @ColumnResult(name="sub_system_code")
    @NamedNativeQuery(name="LoanCapitalization.aggregateStatement", query="SELECT   l.policy_number, l.last_name || ' ' || l.first_name as " +
            "policy_holder, l.amount, c.out_principal_bf as outstanding_loan, c.out_interest_bf as interest, " +
            "SUM (r.repayment_amount) as amount_to_date, c.effective_date, l.sub_system_code FROM loan l JOIN v_latest_capitalization c " +
            "ON l.loan_id = c.loan_id JOIN loan_repayment r ON l.loan_id = r.loan_id WHERE " +
            "c.effective_date BETWEEN ?1 AND ?2 GROUP BY l.policy_number, l.last_name, l.first_name, l.amount, " +
            "c.out_principal_bf, c.out_interest_bf, c.effective_date, l.sub_system_code order by l.sub_system_code, l.last_name",
            resultSetMapping="LoanCapitalization.reportMapping")and
    Query query = entityManager.createNamedQuery("LoanCapitalization.aggregateStatement");
            AggregateStatementLoanBalanceReportData data = null;
            List<AggregateStatementLoanBalanceReportData> returnList = new ArrayList<AggregateStatementLoanBalanceReportData>();
            query.setParameter(1, reportCriteria.getFromDate());
            query.setParameter(2, reportCriteria.getToDate());
            List<Object[]> resultList = query.getResultList();
            System.out.println("resultList.size() >>>>>>>>>> " + resultList.size());
            for (Object[] obj : resultList){
                data = new AggregateStatementLoanBalanceReportData();
                System.out.println("(String)obj[1] >>>>>>>>>> " + (String)obj[1]);
                System.out.println("(String)obj[2] >>>>>>>>>> " + (String)obj[2]);
                System.out.println("(String)obj[3] >>>>>>>>>> " + (String)obj[3]);
                System.out.println("(String)obj[4] >>>>>>>>>> " + (String)obj[4]);
                System.out.println("(String)obj[5] >>>>>>>>>> " + (String)obj[5]);
                System.out.println("(String)obj[6] >>>>>>>>>> " + (String)obj[6]);
                data.setPolicyNumber((String)obj[0]);
                data.setName((String)obj[1]);
    .......My first shocking surpise is that all the System.out.println() return nulls but
    System.out.println("resultList.size() >>>>>>>>>> " + resultList.size()); returned 1.
    so can anyone suggest what the problem may be.
    Regards,
    Michael

    I came across your post as I experienced the same problem. As I found no answers I tried different let's say stupid solutions.
    The one that solved my problem was to write the name for the @ColumnResult in capitals as I noticed that Oracle transforms the alias column names into capitals. I guess otherwise the mapping doesn't occur correctly.
    My example:
    @SqlResultSetMappings({
    @SqlResultSetMapping(
    name = "Customers.searchCustomers",
    entities =
    @EntityResult(entityClass = Customers.class)
    columns =
    @ColumnResult(name = "CONTACTDATE"),
    @ColumnResult(name = "CONTRACTDATE")
    String queryString =
    "SELECT c.CUSTOMER_ID, c.LAST_NAME, c.FIRST_NAME, c.OPU, c.CUSTOMER_CORE_ID, " +
    "to_char(con.CONTACT_DATE, 'yyyy-dd-mm') AS CONTACTDATE, to_char(contr.CONTRACT_DATE, 'yyyy-dd-mm') AS CONTRACTDATE " +
    "FROM CUSTOMERS c " +
    "LEFT JOIN CONTACTS con ON con.CUSTOMER_ID = c.CUSTOMER_ID AND con.ACTIVE = '1' " +
    "LEFT JOIN CONTRACTS contr ON contr.CUSTOMER_ID = c.CUSTOMER_ID AND contr.ACTIVE = '1' " +
    "WHERE c.CAMPAIGN_ID = ?1 AND upper(c.LAST_NAME) LIKE ?2 AND upper(c.FIRST_NAME) LIKE ?3";
    query = em.createNativeQuery(queryString,
    "Customers.searchCustomers");

  • Jpa native query returns only first character of a field

    Hi,
    I've a JPA native query that returns two fields from my oracle database. The first field is a CHAR(2) field with two char values in it, like 'OZ' etc.
    The problem is, as soon as the query is executed it returns only first character of field1. If the actual value of field1 is like 'OZ' then it returns only 'Z'.
    Query nativeQueryForProfileInfo = getManager().createNativeQuery(queryToRun);
    List list = nativeQueryForProfileInfo.getResultList();
    Please help,
    thanks

    There could be several explanations here and it's difficult to say without having more details, possibilities are
    There is something wrong with your display logic.
    There is something wrong with your mapping.

  • Differences between Native Query and Hibernate Native Query?

    What is the differences between this two queries? as i was looking for native query. i saw hibernate native query... from what i've search through the internet, i know noted that hibernate query and native query is a totally different queries
    so is hibernate native query belongs to hibernate query? i m quite confuse 2 differentiate this with native query

    hi,
    Information is retrieved from the data base for use in out programs via a special language known as structured query language (SQL). SQL is a language designed for the use with relational data base systems.
       Open SQL is a subset of native SQL . SQL has been divided into two parts.
    > Open SQL  can recognized by the ABAP program.
    > They are 10 SQL statements out of which we use only 5.
    1. Select.
    2. Insert.
    3. Delete.
    4. Modify.
    5. Update.
    6. Fetch.
    7. Open Cursor.
    8. Close Cursor.
    9. Roll Back.
    10. Commit.
    out of which we use only the first 5.....
    > Native SQL. cannot be recognized by the ABAP program.
    > To execute Native SQL
    Exec SQL.
    End Exec.
    as it cannot be recognized by the ABAP we go for Open SQL.
    If this has helped u solve ur problem then dont forget to reward them with pointrs.
    with regards,
    madhuri.

  • Aggregate function in native query (EJB 3.0)

    How do you run a aggregate function in a native query? I have a particular use case, for reporting purposes, where the result set is too large to fetch the actual CMP collection, thus I need to execute a native count/avg select. I want some thing like,
    Integer totalRecords = (Integer)
           em.createNativeQuery("select count(*) from records").getSingleResult();

    Oracle is intelligent enough to use index only if query result filtering is based on it and result set is less than 5% of the total data set.Sorry to be blunt but that 5% stuff is nonsense.
    Here since the index column is not used in the WHERE clause, oracle performs full table scan.That's not true either. Under the right circumstances the optimizer can use the index, even without a WHERE clause in the query:
    SQL> create table t as select * from dba_objects where object_type is not null;
    Table created.
    SQL> alter table t modify object_type not null;
    Table altered.
    SQL> create index t_idx on t(object_type);
    Index created.
    SQL> explain plan for
      2  select object_type, count(*) from t group by object_type;
    Explained.
    | Id  | Operation             | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |       |    44 |   396 |    60   (7)| 00:00:01 |
    |   1 |  HASH GROUP BY        |       |    44 |   396 |    60   (7)| 00:00:01 |
    |   2 |   INDEX FAST FULL SCAN| T_IDX | 72474 |   636K|    57   (2)| 00:00:01 |
    -------------------------------------------------------------------------------With the OP's query, it (apparently) can not be satisfied by using only the index.
    WHERE TO_CHAR(COL) = TO_CHAR(COL)I don't even know what this means. Usually if you perform a function on an indexed column, the optimizer will not use the index (unless of course it's an fbi).

  • Parameters in Native Query?

    How can I add parameters to a native query?
    The following approach does not work.
    String query = "select * from a where type=:type";
    Query q = em.createNativeQuery(query, A.class);
    q.setParameter("type", 7);
    q.getResultList();
    I get the following exception:
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.8 (Build 060908)): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':type AND contains(GeomFromText('POLYGON((2.47 51.037,4.66 51.037,4.66 51.86,2.4' at line 1Error Code: 1064
    Call:SELECT count(*) AS num FROM shipaction WHERE actiontype_id=:type AND contains(GeomFromText('POLYGON((2.47 51.037,4.66 51.037,4.66 51.86,2.47 51.86,2.47 51.037))'),current_pos)
    Query:ResultSetMappingQuery()
    at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:303)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:551)
    at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:437)
    at oracle.toplink.essentials.threetier.ServerSession.executeCall(ServerSession.java:465)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:213)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:199)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:270)
    at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeSelect(DatasourceCallQueryMechanism.java:252)
    at oracle.toplink.essentials.queryframework.ResultSetMappingQuery.executeDatabaseQuery(ResultSetMappingQuery.java:198)
    at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:609)
    at oracle.toplink.essentials.queryframework.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:536)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2218)
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:937)
    at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:909)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:346)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:471)
    at com.vesseltracker.session.ShipactionUtilBean.countByPolygonAndActionType(ShipactionUtilBean.java:101)

    Hello,
    I had tried it on OC4J with Oracle:
    If q.setParameter(1, 7) had been written
    I've got:
    06/11/16 13:12:01 java.lang.ArrayIndexOutOfBoundsException: 1 > 0
    06/11/16 13:12:01      at java.util.Vector.insertElementAt(Vector.java:558)
    06/11/16 13:12:01      at java.util.Vector.add(Vector.java:776)
    06/11/16 13:12:01      at oracle.toplink.internal.ejb.cmp3.base.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:349)
    06/11/16 13:12:01      at oracle.toplink.internal.ejb.cmp3.EJBQueryImpl.setParameter(EJBQueryImpl.java:178)
    06/11/16 13:12:01      at com.desyde.tmsissue.model.ejb.session.IssueHoursSessionBean.getIssueHoursById(IssueHoursSessionBean.java:74)
    06/11/16 13:12:01      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    06/11/16 13:12:01      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    06/11/16 13:12:01      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    06/11/16 13:12:01      at java.lang.reflect.Method.invoke(Method.java:585)
    06/11/16 13:12:01      at com.evermind.server.ejb.interceptor.joinpoint.EJBJoinPointImpl.invoke(EJBJoinPointImpl.java:35)
    06/11/16 13:12:01      at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
    06/11/16 13:12:01      at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
    06/11/16 13:12:01      at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
    06/11/16 13:12:01      at com.evermind.server.ejb.interceptor.system.TxRequiredInterceptor.invoke(TxRequiredInterceptor.java:55)
    06/11/16 13:12:01      at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
    06/11/16 13:12:01      at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
    06/11/16 13:12:01      at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
    06/11/16 13:12:01      at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:86)
    06/11/16 13:12:01      at IssueHoursBean_StatelessSessionBeanWrapper0.getIssueHoursById(IssueHoursBean_StatelessSessionBeanWrapper0.java:72)
    06/11/16 13:12:01      at view.actions.IssuesAction.list(IssuesAction.java:47)
    06/11/16 13:12:01      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    then I've written q.setParameter(0, 7). it helped me to avoid above exception. but I've got another one:
    01:22:07.474--UnitOfWork(1887)--Thread(Thread[ApplicationServerThread-0,5,RequestThreadGroup])--Exception
    [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.DatabaseException
    java.sql.SQLException: ORA-01008: not all variables bound
    Error code: 1008
    Call:select * from a where type=?1
    Query:ReadAllQuery(com.desyde.tmsissue.model.ejb.entity.IssueHours)
    I've tried to modify query in such ways:
    select * from a where type=?
    select * from a where type=?0
    Have got the same exception.
    Could somebody help me?
    Thanks.

  • Designing LOV Query Problem

    Hello APEX people,
    I posted my problem here:
    Designing LOV Query Problem
    What I have is a sequence like this:
    CREATE SEQUENCE
    DR_SEQ_FIRST_SCHEDULE_GROUP
    MINVALUE 1 MAXVALUE 7 INCREMENT BY 1 START WITH 1
    CACHE 6 ORDER CYCLE ;
    What I need would be a SQL query returning all possible values oft my sequence like:
    1
    2
    3
    4
    5
    6
    7
    I want to use it as a source for a LOV...
    The reason why I use the cycling sequence is: My app uses it to cycle scheduling priorities every month to groups identified by this number (1-7).
    In the Admin Form, I want to restrict the assignment in a user friendly way - a LOV.
    Thanks
    Johann

    Here ist the solution (posted by michales in the PL/SQL forum):
    SQL> CREATE SEQUENCE
    dr_seq_first_schedule_group
    MINVALUE 1 MAXVALUE 7 INCREMENT BY 1 START WITH 1
    CACHE 6 ORDER CYCLE
    Sequence created.
    SQL> SELECT LEVEL sn
    FROM DUAL
    CONNECT BY LEVEL <= (SELECT max_value
    FROM user_sequences
    WHERE sequence_name = 'DR_SEQ_FIRST_SCHEDULE_GROUP')
    SN
    1
    2
    3
    4
    5
    6
    7
    7 rows selected.

  • SQL+-MULTI TABLE QUERY PROBLEM

    HAI ALL,
    ANY SUGGESTION PLEASE?
    SUB: SQL+-MULTI TABLE QUERY PROBLEM
    SQL+ QUERY GIVEN:
    SELECT PATIENT_NUM, PATIENT_NAME, HMTLY_TEST_NAME, HMTLY_RBC_VALUE,
    HMTLY_RBC_NORMAL_VALUE, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE,
    DLC_POLYMORPHS_NORMAL_VALUE FROM PATIENTS_MASTER1, HAEMATOLOGY1,
    DIFFERENTIAL_LEUCOCYTE_COUNT1
    WHERE PATIENT_NUM = HMTLY_PATIENT_NUM AND PATIENT_NUM = DLC_PATIENT_NUM AND PATIENT_NUM
    = &PATIENT_NUM;
    RESULT GOT:
    &PATIENT_NUM =1
    no rows selected
    &PATIENT_NUM=2
    no rows selected
    &PATIENT_NUM=3
    PATIENT_NUM 3
    PATIENT_NAME KKKK
    HMTLY_TEST_NAME HAEMATOLOGY
    HMTLY_RBC_VALUE 4
    HMTLY_RBC_NORMAL 4.6-6.0
    DLC_TEST_NAME DIFFERENTIAL LEUCOCYTE COUNT
    DLC_POLYMORPHS_VALUE     60
    DLC_POLYMORPHS_NORMAL_VALUE     40-65
    ACTUAL WILL BE:
    &PATIENT_NUM=1
    PATIENT_NUM 1
    PATIENT_NAME BBBB
    HMTLY_TEST_NAME HAEMATOLOGY
    HMTLY_RBC_VALUE 5
    HMTLY_RBC_NORMAL 4.6-6.0
    &PATIENT_NUM=2
    PATIENT_NUM 2
    PATIENT_NAME GGGG
    DLC_TEST_NAME DIFFERENTIAL LEUCOCYTE COUNT
    DLC_POLYMORPHS_VALUE     42
    DLC_POLYMORPHS_NORMAL_VALUE     40-65
    &PATIENT_NUM=3
    PATIENT_NUM 3
    PATIENT_NAME KKKK
    HMTLY_TEST_NAME HAEMATOLOGY
    HMTLY_RBC_VALUE 4
    HMTLY_RBC_NORMAL 4.6-6.0
    DLC_TEST_NAME DIFFERENTIAL LEUCOCYTE COUNT
    DLC_POLYMORPHS_VALUE     60
    DLC_POLYMORPHS_NORMAL_VALUE     40-65
    4 TABLES FOR CLINICAL LAB FOR INPUT DATA AND GET REPORT ONLY FOR TESTS MADE FOR PARTICULAR
    PATIENT.
    TABLE1:PATIENTS_MASTER1
    COLUMNS:PATIENT_NUM, PATIENT_NAME,
    VALUES:
    PATIENT_NUM
    1
    2
    3
    4
    PATIENT_NAME
    BBBB
    GGGG
    KKKK
    PPPP
    TABLE2:TESTS_MASTER1
    COLUMNS:TEST_NUM, TEST_NAME
    VALUES:
    TEST_NUM
    1
    2
    TEST_NAME
    HAEMATOLOGY
    DIFFERENTIAL LEUCOCYTE COUNT
    TABLE3:HAEMATOLOGY1
    COLUMNS:
    HMTLY_NUM,HMTLY_PATIENT_NUM,HMTLY_TEST_NAME,HMTLY_RBC_VALUE,HMTLY_RBC_NORMAL_VALUE     
    VALUES:
    HMTLY_NUM
    1
    2
    HMTLY_PATIENT_NUM
    1
    3
    MTLY_TEST_NAME
    HAEMATOLOGY
    HAEMATOLOGY
    HMTLY_RBC_VALUE
    5
    4
    HMTLY_RBC_NORMAL_VALUE
    4.6-6.0
    4.6-6.0
    TABLE4:DIFFERENTIAL_LEUCOCYTE_COUNT1
    COLUMNS:DLC_NUM,DLC_PATIENT_NUM,DLC_TEST_NAME,DLC_POLYMORPHS_VALUE,DLC_POLYMORPHS_
    NORMAL_VALUE,
    VALUES:
    DLC_NUM
    1
    2
    DLC_PATIENT_NUM
    2
    3
    DLC_TEST_NAME
    DIFFERENTIAL LEUCOCYTE COUNT
    DIFFERENTIAL LEUCOCYTE COUNT
    DLC_POLYMORPHS_VALUE
    42
    60
    DLC_POLYMORPHS_NORMAL_VALUE
    40-65
    40-65
    THANKS
    RCS
    E-MAIL:[email protected]
    --------

    I think you want an OUTER JOIN
    SELECT PATIENT_NUM, PATIENT_NAME, HMTLY_TEST_NAME, HMTLY_RBC_VALUE,
    HMTLY_RBC_NORMAL_VALUE, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE,
    DLC_POLYMORPHS_NORMAL_VALUE
    FROM PATIENTS_MASTER1, HAEMATOLOGY1,  DIFFERENTIAL_LEUCOCYTE_COUNT1
    WHERE PATIENT_NUM = HMTLY_PATIENT_NUM (+)
    AND PATIENT_NUM = DLC_PATIENT_NUM (+)
    AND PATIENT_NUM = &PATIENT_NUM;Edited by: shoblock on Nov 5, 2008 12:17 PM
    outer join marks became stupid emoticons or something. attempting to fix

  • ORA-00932 in Native Query

    Hello.
    I'm using some native queries in my EJB 3.0 project.
    When I write a native query like
    INSERT INTO SOME_TABLE VALUES (:val0, :val1, :val2) and use the executeUpdate() method of the Query interface after assigning all parameters to values other than null everything works OK.
    However, if I let any of the values be null (even though that exactly what I want to put in the database) I get the following exception:
    java.sql.SQLException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
    Is there any way to go arround this? I really must write the nulls to the database.
    Thanks in advance,
    Hugo Oliveira
    [email protected]

    Do you mean writing a query like
    "INSERT INTO SOME TABLES VALUES :val0, NULL, :val2"
    instead of
    "INSERT INTO SOME TABLES VALUES :val0, :val1, :val2"
    where the val1 parameter would be assigned a null variable, or passing a null directly in setParameter (query.setParameter("val1", null)) instead of a null variable (query.setParameter("val1", nulVar))?
    Hugo Oliveira
    [email protected]

  • JPA  using native query - distinct

    Hi All,
    Kindly suggest on the following,
    I am facing issues on using the distinct keyword in JPA, Ful details on the following OTN thread.
    JPA  using native query - distinct
    Any help is much appreciated
    VR

    Any ideas ?

  • Can't read with native query a type of CHAR(2)

    I'm working with mysql 5 /EJB3/JDK6
    I want from a nativequery read a field of CHAR(n) in a database, when I user varchar , it s works, but if i use char(n), I always get a java.lang.Character instead of a String.
    CREATE TABLE testchar(
    myid CHAR(2) PRIMARY KEY
    )When i user native query to retrive data then I get a java.lang.Character instead of a String.
    q=em.createNativeQuery("SELECT myid FROM testchar");
    q.setMaxResults(2);
    List<Object[]> r= q.getResultList();
    log.info("class="+ r.get(0).getClass()+" "+r.get(0));
    -->return java.lang.Character and value is the first character of the row     There is someone who have an idea of what is wrong?
    Thanks

    the fact that you are using a native query is the first thing that is wrong. The only time you need a native query is when you want to do something database specific. IF you do something database specific, I hope you have thought deep and hard about really needing it.

Maybe you are looking for

  • How to delete the duplicates in the scneario

    Hi I was created one staging table(10 columns) and uploaded sales order details and Invoice Details in to the same staging table. Here transaction type is SO and INV Requirement is: If the invoice created for the sales order delete those sales orders

  • Issues with converted Inkscape SVG files

    I've been downloading a lot of SVG files, most of which were created with Inkscape, from openclipart.org recently. I've had to open them in Illustrator and save them in .ai format before placing them in an InDesign document as InDesign doesn't accept

  • Need help regarding 5.1 audio on sblive va

    dear users, i m tight on budget thats y cant afford the audigy series or any new hifi cards.. i need help in activating 5. audio on my sbli've value card though old but i always love it.. theres a feature li've surround and when i activate it my surr

  • No WorkItem, No Workflow is Triggered in HR Process and Form Sceniro

    Hi Iu2019ve an issue in triggering a workflow on HCM (i.e.) HR Process & form scenario. Initially the workflow is worked fine when the HCM application is in Dynpro for Java tech. But after the installation of  Enchance.pack 2 where the same Std.appli

  • How to connect to an Oracle database on one machine from another client machine?

    I installed oracle database 11g (server and client) on one machine. It works perfectly. Then I installed oracle client (ODTwithODAC1120320) in another machine. Now I want to connect to the database of the previous machine. I tried to connect but It f