[JPA] SELECT NEW inside SELECT NEW in Named Query

Suppose i have two JPA entities Master and Detail as follows:
@Entity
public class Master implements Serializable{
    private static final long serialVersionUID = 1L;
    private long id;
    private String masterField1;
    private String masterField2;
    private String masterField3;
     private String masterField4;
    private String masterField5;   
    //A lot of other fields till masterFieldn...
    private String masterFieldn;
    private List<Detail> detailList;
    //getters and setters here...
    @OneToMany(mappedBy = "master", cascade = { CascadeType.ALL }, fetch=FetchType.EAGER)
    @OrderBy("detailField1 DESC")
    public List<Detail> getDetailList() {
        return detailList;
@Entity
public class Detail implements Serializable{
    private static final long serialVersionUID = 1L;
    private long id;
    private String detailField1;
    private String detailField2;
    private String detailField3;
     private String detailField4;
    private String detailField5;   
    //A lot of other fields till detailFieldn...
    private String detailFieldn;
    private Master master;
    //getters and setters here...
    @ManyToOne
    @JoinColumn(name="MASTER_ID", referencedColumnName="ID")    public Master getMaster() {
        return master;
    }Both Master and Detail entities have a lot of fields, but i only need a subset of those fields when these entities are queried. So, i have two helper classes which i use in named queries in Master JPA entity :
@NamedQueries({
        @NamedQuery(name = "Master.findMaster",
            query = "SELECT NEW MasterHelper(" +
                "t.masterField1, t.masterField2, t.masterField3, " +
                " SELECT NEW DetailHelper(" +
                "td.detailField1, td.detailField2, td.detailField3 FROM Detail td WHERE " +
                " td.master.id = t.id)) FROM Master t WHERE t.id = ?1")MasterHelper and DetailHelper have only the fields i want to query, getters and setters, and a constructor matching the SELECT NEW.. in @NamedQuery :
public class MasterHelper implements java.io.Serializable {
    private String field1;
    private String field2;
    private String field3;
    private <DetailHelper> detailList;
    //Constructor matching SELECT NEW
    public MasterHelper(String field1, String field2, String Field3, List detailList) {
       this.field1 = field1;
        this.field2 = field2;
        this.field3 = field3;
        this.detailList = detailList;
     //getters and setters
public class DetailHelper implements java.io.Serializable {
    private String field1;
    private String field2;
    private String field3;
    //Constructor matching SELECT NEW
    public DetailHelper(String field1, String field2, String Field3) {
       this.field1 = field1;
        this.field2 = field2;
        this.field3 = field3;
     //getters and setters
}So, basically when i query for a particular Master entity, what i want in return is a List of MasterHelper objects with just the fields i want; each MasterHelper object must include a list of MasterDetail objects, again with just the fields i want.
When the above named query is executed by Toplink Essentials against an Oracle database, i get the following exception regarding the "second" SELECT NEW:
EJBQLException
Exception Description: Syntax error parsing the query [SELECT NEW
...unexpected token [SELECT]
...How can i achieve what i want? Doesn't JPA allows SELECT NEW inside SELECT NEW in named queries?
Thanks in advance for any help.
Edited by: savas_karabuz on May 16, 2008 3:59 AM
Edited by: savas_karabuz on May 16, 2008 4:02 AM

Hello,
The build you are using is an older one, and there have been a few enhancements done for constructor expressions support (for instance
https://glassfish.dev.java.net/issues/show_bug.cgi?id=1421)
but an enhancement to allow constant values is still open: https://glassfish.dev.java.net/issues/show_bug.cgi?id=2452
Best Regards,
Chris

Similar Messages

  • Fetching a value from a select statement inside select clause

    hello all,
    I have a problem executing a procedure it gives me a runtime error, what am doing is i have multiple select statement inside a select clause. am using the entire select statement for a ref cursor. when running the query seperately am able to get the records but it's not getting compiled.
    here is the piece of code which am working with
    create or replace procedure cosd_telecommute_procedure
    (p_from_date in date,
    p_to_date in date,
    p_rset in out sys_refcursor)
    as
    p_str varchar2(10000);
    begin
    p_str := 'select personnum, '||
    'fullname, '||
                   'personid, '||
         'hours, '||
         'applydtm, '||
    'paycodeid, '||
         'laborlev2nm, '||
         'laborlev3nm, '||
         'laborlev2dsc, '||
    'adjdate, '||
         'timeshtitemtypeid, '||
         '(select max(eff_dt) from cosd_telecommute_info_tbl '||
         'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt between ''01-aug-2005'' and ''30-aug-2005'') thisyreffdt, '||
                   '(select elig_config7 from cosd_telecommute_info_tbl '||
                   'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt = (select max(eff_dt) from cosd_telecommute_info_tbl '||
                   'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt between ''01-aug-2005'' and ''30-aug-2005'')) thisyrmiles,'||
    '(select max(eff_dt) from cosd_telecommute_info_tbl '||
                   'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt between trunc(p_from_date) and trunc(p_to_date)) fiscalyreffdt, '||
         '(select elig_config7 from cosd_telecommute_info_tbl '||
                   'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt = (select max(eff_dt) from cosd_telecommute_info_tbl '||
                        'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt between trunc(p_from_date) and trunc(p_to_date))) fiscalyrmiles '||
    'from cosd_vp_telecommute '||
    'where trunc(applydtm) '||
    'between p_from_date and p_to_date '||
                   'and personnum = ''029791''';
                   open p_rset for p_str;
    end cosd_telecommute_procedure;
    and here is the piece of error am getting
    ERROR at line 1:
    ORA-00904: invalid column name
    ORA-06512: at "TKCSOWNER.COSD_TELECOMMUTE_PROCEDURE", line 40
    ORA-06512: at line 5

    Did you run the query in SQL plus? Check whether all the column are valid in your database. Below is the query which i got from your procedure just run and check it out. It is really hard for us to tell you the problem without knowing the table structure
    select personnum, fullname, personid, hours, applydtm, paycodeid, laborlev2nm, laborlev3nm,
    laborlev2dsc, adjdate, timeshtitemtypeid,
    (select max(eff_dt) from cosd_telecommute_info_tbl
      where emplid = cosd_vp_telecommute.personnum
      and eff_dt between '01-aug-2005' and '30-aug-2005') thisyreffdt,
      (select elig_config7 from cosd_telecommute_info_tbl where emplid = cosd_vp_telecommute.personnum
      and eff_dt = (select max(eff_dt)
                    from cosd_telecommute_info_tbl
                    where emplid = cosd_vp_telecommute.personnum
                    and eff_dt between '01-aug-2005' and '30-aug-2005'
       ) thisyrmiles,
      (select max(eff_dt)
       from cosd_telecommute_info_tbl
       where emplid = cosd_vp_telecommute.personnum
       and eff_dt between trunc(p_from_date) and trunc(p_to_date)
       ) fiscalyreffdt,
       (select elig_config7 from cosd_telecommute_info_tbl where emplid = cosd_vp_telecommute.personnum
       and eff_dt = (select max(eff_dt)
                     from cosd_telecommute_info_tbl
                     where emplid = cosd_vp_telecommute.personnum
                     and eff_dt between trunc(p_from_date) and trunc(p_to_date)
       ) fiscalyrmiles
    from cosd_vp_telecommute
    where trunc(applydtm) between p_from_date and p_to_date
    and personnum = '029791'

  • Selecting objects inside selection window only?

    is there a way, that objects only inside the selection window or lassoed region get selected rather than objects getting selected which are partially inside the selection window?

    You may find the following thread/scripts to be helpful.
    How to select only objects within a selection marquee?
    http://forums.adobe.com/thread/856221?start=0&tstart=0
    See Posts: 11, 41, 54

  • If i selected to "Create a new backup" and then cancelled that option but want to go back and select "Inherit backup history"; how do i go back and do that since now when i plug in my HD, that option doesn't appear anymore?? Any Help?

    If i selected to "Create a new backup" and then canceled that option but want to go back and select "Inherit backup history"; how do I go back and do that since now when I plug in my external hard drive, that option doesn't appear anymore?? Any Help? I bought a MacBook Air, but decided to return it for the newest model, and I wanted to back it up so that I can then back it up on my new MacBook Air. I didn't understand the option to Inherit or start a new back up, and therefore selected the option to create a new backup. I believe I should have selected to Inherit backup history so that when i back it up on the new MackBook Air, it appears the same as the one I'm returning.... Is there anyway that i can re-select the option to Inherit backup history for time machine?

    Thanks for sharing this link.
    I've posted a question here https://discussions.apple.com/message/22049103#22049103 describing my situation. Are you able to suggest me the right option?

  • The only way I can open a new tab is by right-clicking a bookmarked site and selecting "Open in a New Tab." I can't click on the New Tab + or CTR+T or open via File. WHY?!?

    The only way I can open a new tab in Firefox is by right-clicking a bookmarked site and selecting "Open in a New Tab." I can't click on the New Tab + or CTR+T or open via File. WHY don't the other means work?

    The Ask Toolbar is causing that in the Firefox 3.6.13+ versions. Uninstall that extension.
    There are a couple of places to check for the Ask toolbar:
    * Check the Windows Control panel for the Ask Toolbar - http://about.ask.com/apn/toolbar/docs/default/faq/en/ff/index.html#na4
    * Also check your list of extensions, you may be able to uninstall it from there - https://support.mozilla.com/kb/Uninstalling+add-ons

  • Could not find selected item matching value "New" warning message in ADF

    Hi,
    I have a selectOneChoice1 for a field which has the following fixed values in it. And while creating it, I selected the 'SelctionRequired' option so that this field will always have a value.
    New
    Pending
    Completed.
    While navigating to this page, I am trying to set the value to 'New' (Retrieved from the DB) in the backing bean. But when the page is rendered, the above field is empty with the above options in the list and jdev has the follwing error message in its log.
    WARNING: Could not find selected item matching value "New" in CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=selectOneChoice1]
    Can any one help me with this issue?
    Thanks,
    Priya

    The value of a list binding is the zero-based integer position in the list that is selected, not the actual underlying value.
    The simplest way to set the value of an attribute is to use an attribute binding (which can be bound to the same attribute as the list binding). When you set the value of an attribute binding, it sets the value as you supply it. Otherwise, you'd need to set the list binding's value to the numerical "slot" number of the one you want to change the value to.

  • When I right click and select open link in new tab, it leaves the page I am on and takes me to the first tab to the right

    I usually have many tabs open when I read the news, and it is nice to select open links in new tabs while scrolling through a news' home page. Lately, however, Mozilla has been opening the new tab, but switches the page I am viewing to the first tab to the right of the home page. For example, I had ESPN.com open, and then a few Facebook tabs after that to the right. Whenever I would select open link in new tab, the tab I was viewing would switch from ESPN.com to the first Facebook tab to the right, and the new tab would open a little further down the line. Any chance anyone knows how to fix this?

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]

  • Cannot select name when creating new DC

    Hi all,
    It seems I encounter this kind of problems over and over again when dealing with NWDI )-:
    In this thread Cannot select vendor when creating new DC I couldn't select vendor.
    I installed a new NWDI system (version is 7.18), did all the post installation steps including the configuration of a name server on the SLD but I cannot select "name" and the vendor I entered is not shown (even if enter it manually I cannot select name so it doesn't help - see snapshot).
    [snapshot|http://img134.imageshack.us/i/nwdi.jpg/]
    Snapshot: http://img134.imageshack.us/i/nwdi.jpg/
    I did name server config on : http://server:port/dtr/system-tools/administration/NameServerConfiguration
    Name prefixes are defined under 'Name Reservation -> Development Component Name' - I used <x.y>/* and <x.y>/tst (x.y is namespace like com.omri).
    I updated CMS after setting the name server, restart J2EE and did all kind of voodoo without success.
    I use local SLD which is part of the J2EE.
    I don't get any error messages (from NWDI/SLD/NWDS).
    I don't remember this kind of problem with NWDI on 6.40 versions.
    Moreover I installed and configured several systems on 7.12 & 7.13 versions without any problems but with 7.14 & 7.18 I've problem with setting the name server...
    Please help,
    Thanks,
    Omri

    Solved it on my own by deleting and creating the track again (with the same settings!!!)

  • Firefox restores (expands) all reduced windows from the Taskbar everytime I select "Open In A New Window" for a link.

    Nightwolfx03 has asked this same question as question #822903, but with different wording. To maximize the matches for searches, I'm re-stating it.
    When I right click on a link and select "Open Link In New Window" to display a new webpage, Firefox restores (expands) ALL the windows which have been minimized on my taskbar. Multiple windows cascade upwards onto my screen, taking several seconds and being incredibly annoying. HELP!

    This issue can be caused by the ASK.com Toolbar
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • NEED HELP - - Inputting data files into a table, Selecting from previous to put in new table, Saving new table

    I am trying to import data characters from a tab delimited file into a table in labview.  After I import the strings, I want to be able to select individual strings from the table and put into another table.  I want the item that I am selecting to appear in a text box labeled 'selected step'.  After I put all of the selected data in the new table, I want to be able to save that table in another tab delimited file (spreadsheet).  This is what I have so far.  Any help given will be GREATLY appreciated. 
    Attachments:
    Selector.zip ‏30 KB

    Hi,
         Here are modifications to your vi to do what you are describing. It helps, when trying to work through issues like these on this forum to not start a new thread with each iteration of your question. Those of us that are trying to help can follow it better if you just "Reply" to your previous thread with the new, related question. If the question is for a totally new issue then a new thread is best, but when you are working through the details of essentially the same problem it really helps us follow it if you stay in one thread, and that usually means faster answers.
    We also like it if, when an answer helps, you give us a rating (the more stars the better) as it is about all we get out of it!
    P.M.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion
    Attachments:
    SelectorV2.zip ‏30 KB

  • You should run a new contract selection for item 0000000010

    Hello Friends
    i am trying to create a service request from WEB IC by confirming Account and Ibase and able to create without error.
    if i end session and open the service request in change mode and if delete the ibase and save, then appeas the below message
    "You should run a new contract selection for item 0000000010", going through OSS notes, but found nothing.
    Transaction type ZXXX : we set
    Contract Determination is set to 'E' : Assign at Item leve : Assign immediately if unique for .
    if i open the service ticket in CRMD_ORDER and go in change mode if i click process action button next to error, this will disappear. but it comes when i assing a ibase to the request, so its working only when i first create without errors.
    users do not use crmd_order to process error and WEB CI does not have process action feature.
    any sort of help will be appreciated.
    Thanks
    Gopi

    Hi Gopi,
    Which release are you using ?
    This message appears when you change any field in the service ticket which has an influence on contract determination, such as ibase, ibase component, line item, ...
    As of CRM2007 we have enabled a hyperlink for this message. Clicking the hyperlink will re-execute the contract selection.
    Regards
    Gert

  • V.15 and New Data Selection

    Hi,
    in V.15 transaction the "New data selection" is greyed out. How can i allow the user to check/uncheck this box?
    The problem is when the "New data selection" is checked and when i execute the transaction, the "Name of sold-to party" is empty but when it's unchecked it's filled ... strange. What is the "New data selection" means?
    Thank you for your replies.

    if you do not select "new data selection" the program with just import previously selected data (the data from previous run which was stored - it's done by selecting "save dataset").
    "New data selection"  means the data is selected from database tables again instead of importing previously selected dataset from storage.
    I believe if you at least once SAVE dataset - the option "new data selection" will be editable, SAP just saves datasets per user, so if user have not saved any dataset - the only option is to run with "new data selection" = 'ON' .

  • I want all new windows to open in tabs but they dont, even after I have selected the option " Open new windows in new tab instead"

    Al the details are in the question: I want all new windows to open in tabs but they dont, even after I have selected the option " Open new windows in new tab instead"

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]

  • Just updated my photoshop cc and wanted to try out the new focus selection tool but it's not there.  Why isn't it there?

    Just updated my photoshop cc and wanted to try out the new focus selection tool but it's not there.  Why isn't it there?

    Use menu Help>About Photoshop make you have started CC 2014 and have not started CC... Its in menu Select under Color range

  • When I select HTML from Create New, it appears in Doc tab as untitled-1.XHTML

    Every time I select HTML from Create New in the Welcome screen, it appears in the Document tab as untitled-1.XHTML, with a green icon.  In the past it's always come up as document-1.html, with no icon, as in my textbook.  I don't know why it's doing this, whether it's important (I would guess that it is), or how to change it.  I'm new to Dreamweaver.  Any help would be much appreciated...

    Which version and build # of DW do you have?  You'll find it under Help > About Dreamweaver.
    Also, which preferences have you specified for new documents?
    Go to Edit > Preferences > New Document. 
    The default extension should be either  .htm or .html, .shtml or .php -- depending on the type of files you work with most. 
    Nancy O.

Maybe you are looking for

  • Forms Migration Document 6i to 10g?

    I have searched OTN and Metalink and cannot find a migration document. I'm installing Forms/Reports 9.0.4 on a new server and moving all my 6i forms/reports. Is there a migration document telling me what changes need to be made in forms/reports for 9

  • Including helper classes in java proxy jar file

    I must not be using the right header search criteria because I'm sure this question has been asked before. In a Web Service File (.jws) I've imported a couple of helper classes that function as data transfer objects. I did this to maintain consistenc

  • How can i tell what itunes version i'm running?

    how can i tell what itunes version i'm running?

  • Can't import certificate after eDir 8.8.2 upgrade

    Folks, I've trawled through most of the posts where this has been in issue, but I can't seem to get Tomcat to import the updated LDAP keystore certificate. Over the weekend I upgraded my NetWare 6.5 servers to eDirectory 8.8sp2. The upgrade went smoo

  • Recorded Training Project not Playing inside of a Project

    I am using V5 and I am having an issue with getting a training project/swf to play within another project. When I view the training project by itself, it plays beautifully, but when I try to get it to work within my larger project no such luck. I hav