Update with subquery in TopLink ?

I want to activate the user account updating its status to ACTIVE.
UPDATE PujUserEntity as user SET user.status.id = (SELECT status.id from PujUserStatusEntity status WHERE status.tag='ACTIVE') WHERE user.login= :login AND user.email= :email
the error during the deployment on Glassfish (TopLink):
CLI171 Command deploy failed : Deploying application in domain failed;
Exception Description: Syntax error parsing the query [activateUserAccount: UPDATE PujUserEntity as user SET user.status.id = (SELECT status.id from PujUserStatusEntity status WHERE status.tag='ACTIVE') WHERE user.login= :userLogin AND user.email= :userEmail], line 1, column 52: unexpected token [SELECT].
Internal Exception: line 1:52: unexpected token: SELECT

According to JPA specification you are not allowed to use subquery in that place. In SET part you can only use simple_arithmetic_expression | string_primary | datetime_primary | boolean_primary | enum_primary | simple_entity_expression | NULL (JSR 220 Java Persistence API specification page 104). You should be able to use native query, or find status.id first and then just pass it as parameter.

Similar Messages

  • Merge Vs Update with Subquery

    What is the main difference between Merge Statment(only update) with simple Update statement based on Select query ?
    Which one is faster ?

    There are no vanilla answers to such a question especially when asked by someone who doesn't have time to post version number or DML.
    The only honest answer ... build a test environment and test it using EXPLAIN PLAN and SET TIMING ON.
    That said: A merge statement should only be used where it is appropriate.

  • Update with subquery

    I want to update a table with data extracted from a xmltype.
    But Oracle extracts only the first value from the subquery.
    Am I missing something or this is the expected output...
    drop table t
    create table t(id number, val varchar2(20));
    insert into t(id, val) values (1, null)
    insert into t(id, val) values (2, null)
    select *
    from t
    ID     VAL
    1     
    2     
    update t set(val) =
    (select t.id from dual)
    where id = t.id
    select *
    from t
    ID     VAL
    1     1
    2     2
    update t set(val) =
    (select extractValue(
                   extract(xmltype('<root>'||
                                       '<node id="1">'||
                                       '<value>1</value>'||
                                       '</node>'||
                                       '<node id="2">'||
                                       '<value>2</value>'||
                                       '</node>'||
                                       '</root>'),
                             '//root/node[@id='||to_char(t.id)||']'),
                   '/node/value') from dual)
    where id = t.id
    select *
    from t
    ID     VAL
    1     1
    2     1 -- <-- should be 2!

    Hi,
    try this way:
    SQL> CREATE TABLE tab AS SELECT 1 id,cast(NULL AS VARCHAR2(20)) val FROM dual UNION ALL
      2                      SELECT 2,NULL FROM dual;
    Table created.
    SQL> DESC tab;
    Name                                      Null?    Type
    ID                                                 NUMBER
    VAL                                                VARCHAR2(20)
    SQL>
    SQL> SELECT * FROM tab;
            ID VAL                                                                 
             1                                                                     
             2                                                                     
    SQL>
    SQL> UPDATE tab t
      2  SET val=(
      3      SELECT
      4         extractValue(
      5            extract(
      6               XMLType('<root>
      7                          <node id="1">
      8                            <value>1</value>
      9                          </node>
    10                          <node id="2">
    11                            <value>2</value>
    12                          </node>
    13                        </root>')
    14               ,'/root/node[@id='||id||']')
    15            ,'/node/value') va
    16      FROM tab s
    17    WHERE t.id=s.id) ;
    2 rows updated.
    SQL> SELECT * FROM tab;
            ID VAL                                                                 
             1 1                                                                   
             2 2                                                                   
    SQL> spool off;btw, you don't need to || every line in xml, and you don't need to do to_char() when using ||
    Ants

  • Insert / update with subquery

    Hi,
    i have to insert (if records don't exist) or update (if records already exist) records from table S into table D. S and D have the same structure.
    Table S
    ID NUMBER, Primary Key,
    DESC1 VARCHAR
    DESC2 VARCHAR
    Table D
    ID NUMBER, Primary Key,
    DESC1 VARCHAR
    DESC2 VARCHAR
    Are this statements OK?
    INSERT INTO D
    ( SELECT * FROM S T1 WHERE NOT EXISTS
    ( SELECT '1' FROM D T2 WHERE T2.ID = T1.ID));
    UPDATE D T1
    SET (DESC1, DESC2) =
    (SELECT DESC1, DECS2
    FROM S T2 WHERE T1.ID = T2.ID ) WHERE EXIST
    ( SELECT '1' FROM S T3 WHERE T1.ID = T3.ID );
    Thanks a lot

    Depends on exist or not the data in
    the destination where id doesn't exists in the source.
    SQL> select * from updatable_tab;
    ID DESC1 DESC2
    1 0 0
    1 0 0
    1 0 0
    1 0 0
    2 f f
    2 f f
    2 f f
    2 f f
    2 f f
    9 rows selected.
    SQL> update updatable_tab dst set (desc1, desc2) =
    2 (select desc1, desc2 from s where s.id = dst.id)
    3 /
    9 rows updated.
    SQL> select * from updatable_tab;
    ID DESC1 DESC2
    1 A A
    1 A A
    1 A A
    1 A A
    2 B B
    2 B B
    2 B B
    2 B B
    2 B B
    9 rows selected.
    But if you have the row in the destination table
    wich does not exists in the source table, it will
    nullify your dest1 and dest2.
    In this case you should of course:
    SQL> select * from updatable_tab;
    ID DESC1 DESC2
    1 0 0
    1 0 0
    1 0 0
    1 0 0
    2 f f
    2 f f
    2 f f
    2 f f
    2 f f
    3 m m
    10 rows selected.
    SQL> select * from s;
    ID DESC1 DESC2
    1 A A
    2 B B
    SQL> update updatable_tab dst set (desc1, desc2) =
    2 (select desc1, desc2 from s where s.id = dst.id)
    3 where exists (select null from s where s.id = dst.id)
    4 /
    9 rows updated.
    SQL> select * from updatable_tab;
    ID DESC1 DESC2
    1 A A
    1 A A
    1 A A
    1 A A
    2 B B
    2 B B
    2 B B
    2 B B
    2 B B
    3 m m
    Rgds.

  • Update with exists and subquery

    Hi how to pass index to this sql
    Table pap ( eqid,seq,histseq,docno,status,value1,value2)
    PK(eqid,seq,histseq) and indx (docno)
    table pa ( eqid,seq,docno,status,value1,value2)
    PK(eqid,seq) and indx (docno)
    update pa
    set (value1,value2) = (select pap.value1,pap.value2 from pap
    where pap.eqid = pa.eqid
    and pap.seq = pa.seq
    and pap.histseq =1
    and pap.docno <> pa.docno
    and pap.status = 4 )
    where pa.status=1
    and exists ( select 1 from pap
    where pap.eqid = pa.eqid
    and pap.seq = pa.seq
    and pap.histseq =1
    and pap.docno <> pa.docno
    and pap.status =4 )
    It is doing fulltable scan on pa and using hash join .
    How to write update with subquery method also ?

    There's nothing wrong with a full scan.
    Please read this explanation/example: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9422487749968
    If you want more explanation then please follow these guidelines below, so we have sufficient inputs:
    [When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
    [How to post a SQL statement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
    Remember to put the tag befor and after the examples you post.
    See http://forums.oracle.com/forums/help.jspa regarding tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Update column with subquery returning more than one row

    Hi Everybody,
    Please let me know how to handle this. I am writing update statement in procedure with subquery and it is returning multiple rows. Please help me, how i can handle this :
    UPDATE TABLEA A
    SET A.ERROR_MESSAGE = (Select B.XERROR_MESSAGE from TABLEB B, TABLEA A WHERE B.id = A.id)
    WHERE A.id = (Select B.id from TABLEB B, TABLEA A WHERE B.id = A.id);
    (Select B.XERROR_MESSAGE from TABLEB B, TABLEA A WHERE B.id = A.id) --- This subquery is returning more than one rows. How i can handle this in Pl/SQL?
    Please let me know. I will be very thankful to you all.
    I will really appreciate your replies and comments.
    Thank you

    Try getting rid of tablea in your subqueries. You already have it in the UPDATE statement.
    UPDATE TABLEA A
    SET    A.ERROR_MESSAGE = (Select B.XERROR_MESSAGE
                              from   TABLEB B
                              WHERE  B.id = A.id
    WHERE  A.id = (Select B.id
                   from   TABLEB B
                   WHERE  B.id = A.id);You can also try a simple MERGE:
    merge into tablea a
    using tableb b
    on    (a.id = b.id)
    when  matched then update
          set a.error_message = b.xerror_message;

  • DB polling : query with subquery

    Hi,
    We are upgrading the 10g code to 11g, where one process has the DB polling with custom SQQL. This SQL has a subquery like,
    Select Name, ID, CID from tabl1 where lastdate + (select num_value from table2 where column2 = "xxx") <= sysdate
    We want the similar functionality in 11g. The upgraded code generated few artifiacts like toplink. We have bulilt that and deployed to server. But it is not polling the data eventhough the matching records are present in the tables.
    Please let us know how to fix this issue.
    Thanks,
    Vinoth

    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

  • Update with Outer Join

    Is it possible to do an update that involves an outer join on the table being updated?
    Here's what I mean - currently, I have something like:
    UPDATE table_1 t1
    SET col_1 =
    SELECT t2.col_2
    FROM table_2 t2
    WHERE t2.t1_key = t1.t1_key
    WHERE EXISTS
    SELECT t2.*
    FROM table_2 t2
    WHERE t2.t1_key = t1.t1_key
    UPDATE table_1 t1
    SET col_1 = 0
    WHERE NOT EXISTS
    SELECT t2.*
    FROM table_2 t2
    WHERE t2.t1_key = t1.t1_key
    Yes, I could do set all of the table_1.col_1 values = 0 first, and then do the first update, but it is inefficient given the number of records in the table that would be updated twice.
    Is there a way of combining these two updates into a single update statement?

    You could simply use your first update and omit the WHERE EXISTS clause since you want to update all the rows in table_1 anyway.
    If the subquery finds a match, it will update with the selected value. Normally, a non-match would set the column to a null but you can solve that with NVL:
    SQL> select * from table_1;
                  T1_KEY                COL_1
                       1                    1
                       2                    1
                       3                    1
                       4                    1
                       5                    1
                       6                    1
                       7                    1
                       8                    1
                       9                    1
    9 rows selected.
    SQL> select * from table_2;
                  T2_KEY                COL_2
                       1                    9
                       3                    9
                       5                    9
    SQL> UPDATE table_1 t1
      2  SET    col_1 = nvl (
      3                       (SELECT t2.col_2
      4                        FROM   table_2 t2
      5                        WHERE  t2.t2_key = t1.t1_key
      6                       ),0
      7                     )
      8  ;
    9 rows updated.
    SQL> select * from table_1;
                  T1_KEY                COL_1
                       1                    9
                       2                    0
                       3                    9
                       4                    0
                       5                    9
                       6                    0
                       7                    0
                       8                    0
                       9                    0
    9 rows selected.

  • Why update with subqueries does not have cost and cardinality?

    There is update.
    update test t1 set dummy = (select dummy from test2 t2 where t1.id = t2.id);Both tables which have actual statistics. Each has 1000 rows. And column ID have values from 1 to 1000 in each table.
    This is explain plan
    | Id  | Operation          | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT   |       |  1000 | 13000 |   426   (9)| 00:00:01 |
    |   1 |  UPDATE            | TEST  |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| TEST  |  1000 | 13000 |   426   (9)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TEST2 |     1 |    13 |   426   (9)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter("T2"."ID"=:B1)We can see here, that Oracle consider subquery within update as once-executed subquery.
    This is runtime plan
    | Id  | Operation          | Name  | Starts | E-Rows | A-Rows |
    |   1 |  UPDATE            | TEST  |      1 |        |      0 |
    |   2 |   TABLE ACCESS FULL| TEST  |      1 |   1000 |   1000 |
    |*  3 |   TABLE ACCESS FULL| TEST2 |   1000 |      1 |   1000 |
    Predicate Information (identified by operation id):
       3 - filter("T2"."ID"=:B1)Why first plan does not have cost in step 1?
    Does Oracle always not understand that update with subqueries will performed as NL or filter? In other words that step 3 will executed many times.
    Or it is my bug (or what?)?

    793769 wrote:
    Does Oracle always not understand that update with subqueries will performed as NL or filter? In other words that step 3 will executed many times.
    Or it is my bug (or what?)?It's not possible to say whether this is a bug or a deliberate choice.
    Because of "subquery caching" (see http://jonathanlewis.wordpress.com/2006/11/06/filter-subqueries/ ) the optimizer cannot predict how often the subquery will have to run. So possibly it shows nothing rather than showing the best or worst cases or a pure guess.
    Regards
    Jonathan Lewis

  • Cant open itunes. get error message 7 followed by error message windows error 127.     i have redownloaded new updates with luck.   window xp

    cant open itunes. get error message 7 followed by error message windows error 127.     i have redownloaded new updates with luck.   window xp

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it, which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    tt2

  • I connected my external hard drive to my new imac to put all of the information from my macbook onto it. i have been working on the macbook now and want to reconnect the external hard drive so my imac is updated with the work. How is that done?

    I connected my external hard drive to my new imac to put all of the information from my macbook onto it. I have been working on the macbook now and want to reconnect the external hard drive so my imac is updated with the work. How is that done? or is it possible?

    As I said, I don't use Time Machine, so it'd be best to wait for an "expert" answer, but, with my very limited knowledge, I'd say: probably not - so, for now, I'd suggest you read up on Time Machine:
    http://web.me.com/pondini/Time_Machine/Home.html
    http://support.apple.com/kb/index?page=search&src=support_site.home.search&local e=en_US&q=time%20machine
    And, you might be attracting more knowledgeable answers if you were to post this question in the Time Machine Forum (part of the Snow Leopard forums).

  • Batch Characteristic not updating with result for linked MIC

    Hi,
    I have created a MIC and linked to a batch characteristic i.e. potency and included the characteristic in a specific batch class. This MIC is part of the inspection plan for a certain material.
    If I generate a lot of origin 01 and 09 for the material and record a result for the MIC and apply a UD, the batch characteristic is not updated with the result recorded in the batch master record..
    If I generate a lot origin 89 for the same material, when the result is recorded for the MIC and apply a UD the batch characteristic is updated with the mic value in the batch master record.
    Can you help regards?

    Ok. I am a little bit further.
    I put a trace (ST05) on the result recording and I find a difference between 4.7 and ECC6.0.
    In ECC6.0 I've an deletion in table "AUSP". This deletion isn't performed in the 4.7 system.
    Hope that this can help to solve my problem.
    Regards,
    René
    @ Mayank
    Above, all the master data and customizing is mentioned to transfer the result to the batch classification
    Edited by: Rene Fuhner on Jul 30, 2010 7:03 PM

  • How do you transfer voice memos to your pc?  I have synced my phone a number of times and everything updates with the exception of voice memos?

    How do you transfer voice memos to your pc?  I have synced my phone a number of times and everything updates with the exception of voice memos? Also, my voice memos are checked to be synced everytime my phone is synced. 

    Voice memos, once correctly synced, will appear under your Music Library.  Can you go through your music library to check?

  • Problems with software the update with Nokia 6233

    Problems with software the update with Nokia 6233
    Hello,
    I have so far some-paints tries my software to update.
    Each time the update procedure begins, sometime stands then on the telephone “test mode”.
    On the computer wars I the reference in the update manager “connection to the telephone broken off” and wants the update to again start.
    If I change my profile attitudes since that for example, then after a telephone restart again deleted.
    What there can I make?
    GreetingsMessage Edited by adisaily on 24-Aug-2007 09:03 AM

    It sounds like your 5800 has the earpiece fault that was common with 5800's made before February.
    You need to take it to a nokia care point for repair under warranty.
    Care points/service centres and repair info:
    UK • Europe • Asia-Pacific • USA •
    Canada • Middle East and Africa
    Elsewhere: Click here, select your country, go to the support section, then select repair.

  • I have a column where I have implemented writeback, its working fine. On top of this I need to show 0 as No and 1 as yes in our report, that is also done. Now I want to enter Yes in a column where it was no and I want database table to get update with 1.

    I have a column where I have implemented writeback, its working fine. On top of this I need to show 0 as No and 1 as yes in our report, that is also done. Now I want to enter Yes in a column where it was no and I want database table to get update with 1. I am not sure how to do it. SOmeone please help me out.

    Hi ,
    In your write back XML  try the below  query insert
    INSERT INTO TABLE_XYZ (attribute1)  values (SELECT CASE  WHEN @{C1}=’Yes’ then 1 when @{C1}=’No’ then 0 else null end from dual)
    Regards
    Rajagopal

Maybe you are looking for

  • How can i get emojis on my keyboard ? i have a iPhone 5c

    how can i get emojis on my keyboard ? I have an iPhone 5c

  • Fetching of email address too slow since TB 31

    Since the update to TB 31, fetching email addresses while typing a part of it and hitting tab does not work. Ex. I have an email saved as [email protected] Till the update I would quickly type "samp" and hit tab immediately. It would automatically fe

  • URGENT: How to create Map IDs

    I am using RH7, have inherited a help project in which all topics have been assigned map IDs. I have created several new topics (at the root level) and do not know how to create map IDs for the new topics. I need step-by-step help on how to create ID

  • ALE - Distribution Error

    Hello Experts, I need to add an extension in MATMAS. I created an extension and added to message type Z_MATMAS. Here, my partner system is Siebel. I added Z_MATMAS under one Model View and Generated the partner profile and saved. Here, the problem is

  • TS5223 change icloud e-mail address

    How do I change my e-mail for my iCloud. It won't let me change it on my settings and it's getting really annoying with the iCloud thing popping up asking for my password for the e-mail I don't use it for anymore. I tried reseting the password and th