JPA, Toplink, Query with getSingleResult returns Vector, should it?

I don't understand why when I do a simple query "Select count(*) From ...." and get use the EntityManager my code is something like this:
getEntityManager().createNativeQuery(sql).getSingleResult()
and what I get is a Vector object that has inside a BigDecimal object. I wonder how portable this is if I use hibernate. I bought a book that was written by a couple of guys from Oracle and their example returns a Object array instead of a Vector even when getResultList() function is called.
I can't find any documentation where it indicates what is returned from getSingleResult() and getResultList().
Any help from any gurus are most welcomed....

Bug 2219 (https://glassfish.dev.java.net/issues/show_bug.cgi?id=2219 ) deals with native queries not returning the correct types unless it is to return an entity or results specified using a ResultRetMapping.
Michael's blog examples are all using JPQL which do not have this problem, so you could switch to using JPQL to get the proper results as well.
Best Regards,
Chris

Similar Messages

  • Simple query with like return wrong result

    Hi,
    I run simple query with like.
    If I use parameter I get wrong results.
    If I use query without parameter results are ok.
    My script:
    ALTER SESSION SET NLS_SORT=BINARY_CI;
    ALTER SESSION SET NLS_COMP=LINGUISTIC;
    -- drop table abcd;
    create table abcd (col1 varchar2(10));
    INSERT INTO ABCD VALUES ('122222');
    insert into abcd values ('111222');
    SELECT * FROM ABCD WHERE COL1 LIKE :1; -- wrong result with value 12%
    COL1
    122222
    *111222*
    select * from abcd where col1 like '12%'; -- result ok
    COL1
    122222
    I use Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    and query run in Oracle SQL Developer 3.1.07.

    Hi,
    welcome to the forum.
    When you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    You should specify exactly how you run your code.
    If I run this statement in SQL Plus:SQL> ALTER SESSION SET NLS_SORT=BINARY_CI;
    Session altered.
    SQL> ALTER SESSION SET NLS_COMP=LINGUISTIC;
    Session altered.
    SQL>
    SQL> -- drop table abcd;
    SQL> create table abcd (col1 varchar2(10));
    Table created.
    SQL>
    SQL> INSERT INTO ABCD VALUES ('122222');
    1 row created.
    SQL> insert into abcd values ('111222');
    1 row created.
    SQL>
    SQL> SELECT * FROM ABCD WHERE COL1 LIKE :1;
    SP2-0552: Bind variable "1" not declared.
    SQL>
    I got this error. So I wonder how you set value 12%
    Please specify exactly how you run your test as we cannot reproduce your problem.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Query with XMLTABLE returns null rows

    Hello all,
    I'm trying a query with XMLTABLE, but even thought the number of returned rows is correct, the row content is (null).
    DB version is: 10.2.0.4.0
    Here is my query;
    SELECT s.DESCRIPTION
    FROM EXECUTIONPLAN p,
      XMLTABLE
      ('//executionPlan/executionPlanItems/summary'  
       PASSING p.DATA
       COLUMNS
         DESCRIPTION VARCHAR(250) PATH '/taskId'
      ) s
    WHERE
    trunc(extractValue(data, '/executionPlan/executionPlanHeader/statusChanged')) = to_date('2010-03-05','YYYY-MM-DD');Sorry the XML content is quite big -50k lines at average- so can't post the whole XML, but to give an idea;
    /executionPlan
       /executionPlan
          /executionPlanHeader
             /statusChanged
             /x
             /y
          /executionPlanItems
             /summary
                /taskId
             /summary
             /summary
             ...The result looks like;
    1 (null)
    2 (null)
    3 (null)
    4 (null)
    ...Suggestions are very much appreciated :)
    Cheers

    Hi guys,
    Cracked it at last. It seems the column definition part does not like the forward slash in front of it. The following works;
    SELECT s.DESCRIPTION
    FROM EXECUTIONPLAN p,
      XMLTABLE
      ( XmlNamespaces(DEFAULT 'http://www.staffware.com/frameworks/gen/valueobjects'),
       '/executionPlan/executionPlanItems/summary'  
       PASSING p.DATA
       COLUMNS
         DESCRIPTION VARCHAR(250) PATH 'taskId'
      ) s
    WHERE
    trunc(extractValue(p.data, '/executionPlan/executionPlanHeader/statusChanged'
                             , 'xmlns="http://www.staffware.com/frameworks/gen/valueobjects"')) = to_date('2010-03-05','YYYY-MM-DD');I'm not sure if this is the way it is intended since it seems a bit weird to me and is not in line with the docs - or at least my understanding of them.
    Thanks for taking the time to help out. Now on to coding :)

  • JPA toplink Query cache

    Any idea when performing Query's with Hint but no L2 cache enabled ? Will that object cached / lazyloaded /enriched on access ?
    By the way, whats the default L2 cache setting, is it enable or disabled ? If enable where does it stores, in memory ?
    Thanks
    Newbie

    A shared (L2) cache is enabled by default in TopLink/EclipseLink.
    The cache is in memory.
    Using a query cache, without the shared cache makes little sense, you should use both, or none.
    What will happen if you do is the query cache will be isolated to the session the same as the object cache, so you will get query cache hits for the duration of the persistence context/transaction. i.e. it will be an L1 query cache.
    To configure the cache see,
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching

  • Simple Query with subquery returns the 'wrong' result

    DB version: 11.2
    We created about 27 schemas in the last 4 days. The below query confirms that.
    SQL > select username, created from dba_users where created > sysdate-4;
    USERNAME                       CREATED
    MANHSMPTOM_DEV_01              12 Jul 2012 11:55:16
    PRSM01_OAT_IAU                 13 Jul 2012 01:51:03
    F_SW                           11 Jul 2012 17:52:42
    FUN_CDD_HK_SIT                 09 Jul 2012 15:33:57
    CEMSCOMPTOM_UAT_01             12 Jul 2012 11:43:45
    STORM02_OAT_IAU                13 Jul 2012 02:06:29
    27 rows selected.  -------------> Truncated outputFrom DBA_TS_QUOTAS.max_bytes column , we can determine the space quota allocated for a user/schema
    SQL > desc dba_ts_quotas
    Name                                      Null?    Type
    TABLESPACE_NAME                           NOT NULL VARCHAR2(30)
    USERNAME                                  NOT NULL VARCHAR2(30)
    BYTES                                              NUMBER
    MAX_BYTES                                          NUMBER
    BLOCKS                                             NUMBER
    MAX_BLOCKS                                         NUMBER
    DROPPED                                            VARCHAR2(3)So, I wanted to see the allocated space for the users created in the last 4 days. The below query should return only 27 records because the subquery returns only 27 records. Instead it returned 66 records !
    select username, tablespace_name, max_bytes/1024/1024 quotaInMB
    from dba_ts_quotas
    where username in (select username from dba_users where created > sysdate-4);Any idea why ? I know it is not a bug with oracle. Its just I haven't been eating fish lately.

    Hi,
    J.Kiechle wrote:
    So, I wanted to see the allocated space for the users created in the last 4 days.DBA_TS_QUOTAS doesn't give the allocated space but rather the maximum allowed for a given user.
    J.Kiechle wrote:
    The below query should return only 27 records because the subquery returns only 27 records. Instead it returned 66 records !What if your user John has Quotas on 3 tablespace TBS1, TBS2 and TBS3 ?
    You cannot expect the outer query to only retrieve at most 27 rows just because the inner query returns 27 rows.
    For allocated space by tablespace for recently created users, you'd better query dba_segments. something like :select owner, tablespace_name, trunc(sum(bytes)/1024/1024) alloc_mb
    from dba_segments
    where owner in (select username from dba_users where created > sysdate - 4)
    group by owner, tablespace_name
    order by owner, tablespace_name;

  • SQL query with parameter returns empty result set, please help !!!

    Hi there,
    When I use the following query :
    <sql:query var="beroepsthemas" >
    select *
    from beroepsthemas
    where beroepsthemaid = ?
    <sql:param value="12"/>
    </sql:query>
    When I want to browse the result set with :
    <c:forEach items="${beroepsthemas.rows}" var="rij">
    it shows no records. But it must return at least one.
    All my jsp pages with sql queries and parameters have the same problem.
    This is all on my test environment. I'm using Ubuntu 5.10, Netbeans5.0, JDK 1.5_06, application runs in Bundeled Tomcat 5.5.9, MySQL 4.1.12, mysql-connector3.1.6
    When the same code is run on the live environment, it works just fine.
    The difference is :
    Mysql 4.1.10a, tomcat5.5.9, mysql-connector3.1.6
    What can there be wrong !!

    When the same code is run on the live environment, it
    works just fine.
    The difference is :
    Mysql 4.1.10a, tomcat5.5.9, mysql-connector3.1.6
    I didn't catch this. I think you may need to update the database driver.

  • SQL-Query with JDBC returns error ORA-00600

    Hi,
    I try to execute a SQL-Query using JDeveloper 3.2.3 and the Oracle JDBC-Library 8.1.7
    The following statement
    'ResultSet rset=stmt.executeQuery(SQL-String);'
    where stmt is Statement returns a Database-Error
    ORA-00600 with the Arguments [ttcgcshnd-1], [0] [], [], [], [], [], []
    when the SQL-String queries Varchar2 or CHAR-Columns.
    The Query returns correct values for numeric fields.
    The Database-Server is running on Oracle 9i
    Does anybody know, what could be the reason?
    Thanks, Harold

    I found many forums about it also, but I still haven't got solution yet.
    They talk about the cause, and report to oracle group and so on,
    but I still don't know how to solve my problem and how to enable my oracle 9i jdbc driver working.
    Need help please

  • Help in building Toplink query with Date

    Hi,
    Can any anybody help me on how to build the toplink expression for the date.
    We are passing the date object and I'm getting the date as (Eg:"Sat May 31 16:34:35 EDT 2008").
    When I passing in like this I'm not able to det the data although I got data in the database.
    Expression dateExp = builder.get(testDate").equal("zzzzz.getDate()");
    Any help is appreciated.
    Thanks,
    Basil

    Hello Basil,
    Can you turn on logging and post the sql that gets generated? Also, what is the database/driver version being used, and what is the database column type for the date? This could be a problem with the precision of the date object being passed in not matching the date objects used in the database. If you read an object by its primary key, is the date infomation populated correctly?
    Best Regards,
    Chris

  • Query.getSingleResult returns a Vector?

    Hallo
    I tested on glassfish 2.1 with oracle.toplink.essentials.PersistenceProvider. Running a test with the entitymanager i noticed that getSingleResult returns a vector containing only one element rather than an object that i could cast accordingly.
    Looking in the web and also taking a look at the spec all example cast the result directly rather than assuming a vector/list.
    Since the specification just wants Object as result type this is not wrong but does that really pass compatibility tests?
    regards

    You are right it is not nailed down. From my book and various examples i thought that an Object or Object[] was returned and you then cast accordingly but maybe this is only true for hibernate. Since i am bound to toplink in this case i am screwed.
    Regarding the additional paramaeter, this also fails, i tried that before:
    Query query = em.createNativeQuery("select count(*) from soc",Integer.class); results in [TopLink Warning]: 2010.01.11 06:24:23.070--UnitOfWork(12359283)--Exception [TOPLINK-6007] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))): oracle.toplink.essentials.exceptions.QueryException
    Exception Description: Missing descriptor for [class java.lang.Integer].
    Query: ReadAllQuery(java.lang.Integer)
    Exception in thread "main" Local Exception Stack:
    Exception [TOPLINK-6007] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))): oracle.toplink.essentials.exceptions.QueryException
    Exception Description: Missing descriptor for [class java.lang.Integer].
    Query: ReadAllQuery(java.lang.Integer)
         at oracle.toplink.essentials.exceptions.QueryException.descriptorIsMissing(QueryException.java:419).

  • JPA named query should return only first result

    Hello,
    I'm quite new to JPA.
    How can I return only the first result of a query? This must happen in the database, not by getSingleResult() from the EntityManager because the table has appr. 15 mio entries.
    Does the JP QL provide this? like the LIMIT keyword in MySQL?
    thanks from germany
    Dirk

    I moved this question to: Forum Home » Java Enterprise & Remote Computing » Enterprise JavaBeans
    Donat

  • Query with subquery should return value but doesn't

    When I run this SQL, it returns no value:
    SELECT vfn.cat
    FROM vps_fishery_ner vfn, valid_fishery vf
    WHERE vfn.plan = vf.plan
    AND vfn.cat = vf.cat
    AND vf.permit_year = 2010
    AND vf.moratorium_fishery = 'T'
    AND vfn.vp_num = 211652
    AND vfn.ap_year = 2010
    AND vfn.plan = 'MUL'
    AND vfn.date_issued = (SELECT MAX(date_issued)
    FROM vps_fishery_ner
    WHERE vp_num = 211652
    AND ap_year = 2010);
    In order to test, I take out the subquery and run it separately:
    SELECT MAX(date_issued)
    FROM vps_fishery_ner
    WHERE vp_num = 211652
    AND ap_year = 2010;
    Returns 02-APR-10
    Then I paste this date into the original query (using the TRUNC function, of course, since I hardcode only the DDMMYY part of the date):
    SELECT vfn.cat
    FROM vps_fishery_ner vfn, valid_fishery vf
    WHERE vfn.plan = vf.plan
    AND vfn.cat = vf.cat
    AND vf.permit_year = 2010
    AND vf.moratorium_fishery = 'T'
    AND vfn.vp_num = 211652
    AND vfn.ap_year = 2010
    AND vfn.plan = 'MUL'
    AND TRUNC(date_issued) = TO_DATE('02-APR-10');
    And this returns the required value, 'A'.
    So why doesn't the full query with subquery work, if the value that is returned by the subquery is valid and works when you just paste it in?
    Thanks.

    Hi,
    Not sure about your question.
    But you say when you uss 01-apr-10 you get the expected results.
    So why dont you try using trunc on botht sides
    SELECT vfn.cat
      FROM vps_fishery_ner vfn, valid_fishery vf
    WHERE vfn.plan = vf.plan
       AND vfn.cat = vf.cat
       AND vf.permit_year = 2010
       AND vf.moratorium_fishery = 'T'
       AND vfn.vp_num = 211652
       AND vfn.ap_year = 2010
       AND vfn.plan = 'MUL'
       AND trunc(vfn.date_issued) = (SELECT MAX(trunc(date_issued))
                                FROM vps_fishery_ner
                               WHERE vp_num = 211652
                                 AND ap_year = 2010);Rememeber if you are couting on some Index to be used you might want to recheck.
    IN answer to your question why it does not return with subquery included, because the TIME PART is not the same.
    You yourself proved it by using the supplying only the date part.
    Regards,
    Bhushan

  • Using 'Function Returning SQL Query' with Flash charts

    I have created a pl/sql function that returns a SQL query as a varchar2 of this form:
    select null link
    <x value> value
    <Series1 y value> Series 1 Label
    <Series2 y value> Series 2 Label
    <Series3 y value> Series 3 Label
    from tablea a
    join tableb b
    on a.col = b.col
    order by <x value>
    If I now call the function from a Flash Chart Series SQL box with the Query Source Type set to 'Function Returning SQL Query' like this:
    return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'))
    it parses correctly and the page is saved; however, when I run the page I don't get any output - nor any error messages or other indication of a problem.
    Now, if I call the function in a SQL client, capture the SQL query output using dbms_output and paste that into the Flash Chart Series SQL box - changing the Query Source Type to SQL Query - and save the page it works fine when I run it and returns a multi-series flash chart.
    Can anyone suggest either;
    1. What have I might have missed or done wrong?
    2. Any way to usefully diagnose the problem...
    I have tried using the Apex debugger - which is very nice, by the way - but it doesn't provide any info on what my problem might be. I even tried writing my own debug messages from my function using the apex_debug_message package - got nothing...
    Thanks,
    Eric

    Hi Eric,
    Try expressing the source as this:
    begin
       return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'));
    end;That works fine for me, and if I take out the begin-end and the trailing semicolon from the return statement I get the same behavior as you.
    It does mention in the help for the source (only during the wizard though) that this source type has to be expressed that way, but I agree it would be helpful if the tool would validate for this format when 'Function Returning SQL Query' is used or give some sort of indication of the trouble. Anyway, this should get you going again.
    Hope this helps,
    John
    If you find this information useful, please remember to mark the post "helpful" or "correct" so that others may benefit as well.

  • 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

  • Need help writing a MySQL query that will return only records with matching counter-parts

    Since I don't know how to explain this easily, I'm using the
    table below as an example.
    I want to create a MySQL query that will return only records
    that have matching counter-parts where 'col1' = 'ABC'.
    Notice the 'ABC / GHI' record does not have a
    counter-matching 'GHI / ABC' record. This record should not be
    returned because there is no matching counter-part. With this
    table, the 'ABC / GHI' record should be the only one returned in
    the query.
    How can I create a query that will do this?
    id | col1 | col2
    1 | ABC | DEF
    2 | DEF | ABC
    3 | ABC | GHI
    4 | DEF | GHI
    5 | GHI | DEF
    *Please let me know if you have no idea what I'm trying to
    explain.

    AngryCloud wrote:
    > Since I don't know how to explain this easily, I'm using
    the table below as an
    > example.
    >
    > I want to create a MySQL query that will return only
    records that have
    > matching counter-parts where 'col1' = 'ABC'.
    >
    > Notice the 'ABC / GHI' record does not have a
    counter-matching 'GHI / ABC'
    > record. This record should not be returned because there
    is no matching
    > counter-part. With this table, the 'ABC / GHI' record
    should be the only one
    > returned in the query.
    >
    > How can I create a query that will do this?
    >
    >
    > id | col1 | col2
    > --------------------
    > 1 | ABC | DEF
    > 2 | DEF | ABC
    > 3 | ABC | GHI
    > 4 | DEF | GHI
    > 5 | GHI | DEF
    >
    >
    > *Please let me know if you have no idea what I'm trying
    to explain.
    >
    Please be more clear. You say that 'ABC / GHI' should not be
    returned,
    and then you say that 'ABC / GHI' should be the only one
    returned. Can't
    have both...

  • 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.

Maybe you are looking for

  • Change Plant in SAles order..

    Hi, I'm trying to change the plant in sales order Tcode :Va02->Fast change of -->Plant. Though the plant is enabled when i change it gives me a message "Item:......Plant cannot be copied". Can anybody help me in changing this.Is there any userexit or

  • New computer, itunes picked up my music, but can't sync with my nano

    Old computer died. We moved the old music to the new computer and downloaded itunes. It picked up all of the music/pod casts ect. no playlists though. Put my nano on and it picks it up but won't let me move my newly purchased songs to it or move my p

  • How do I correctly import images into Lightroom?

    Before installing Adobe Creative Cloud, I deleted Adobe Elements and all files in My Pictures on my hard drive so I could start fresh. I copied groups of images from CS5 Bridge on my old pc onto an empty flashdrive and tried to import them to Lightro

  • Blank screen on full screen mode

    Hi everybody, I have windows vista i just installd flash player 9. i have problem that when i press full sreen button on any video on any site its goes blank. i am getting sound but no picture. Can anybody tell me what should be problem.

  • 3 way video conferencing with FaceTime?

    Is it possible between Mac and two IPads?