Can I put a static findByXandY() in my Entity?

Hi,
The examples I find put @NamedQuery in the Entity. Then they put all the code to implement a findByXandY() method in the Session Bean that wants to locate the Entity for X and Y.
That seems a lot of excess code if I have say 10 Session Beans that all need to look up the Entity by X and Y!
Can I get a way with putting a static findBySandY() in the Entity class and then just call it from any Session Bean???
I mean first define MyEntity something like this:
@NamedQueries(
  {  @NamedQuery(name="findByXandY",
                 query="SELECT e FROM Employee e"
                 WHERE e.fieldX = :X, e.fieldY = "Y),
     @NamedQuery(...)
@Entity
public class MyEntity {
  static List findByXandY( EntityManager em, String X, String Y) {
    return em.createNamedQuery("findByXandY")
             .setParameter("X", "xxxx")
             .setParemeter("Y","yyyy")
             .getResultList();
}{code}
Then write my Session Bean something like this:
{code}@Stateless
public class MyServiceBean implements MyServiceLocal {
  @PersistenceContext(unitName="someName") //name assigned in persistence.xml
  private EntityManager em;
  // internal helper method used by the Session Bean
  private List findMyEntityByXandY (String x, String y) {
    return = MyEntity.findByXandY(em,x,y);
{code}
Any hope?
Thanks,
glb                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Opps. I forgot to put
String fieldX; and
String fieldY; and
their setters and getters in MY Entity.
And I guess my private method in the Session Bean is redundent ... silly because if this works, I can just use this line in any Session Bean that needs a MyEntity row whose relevant fields are "xx and "yy".
List MyEntity.findByXandY(em,"xx","yy");
glb

Similar Messages

  • Can i put ME-SYNC_USER in T01?

    Hi, i did an application with syncbo S01, and i put the ME-SYNC_USER in each syncbo...
    Now, i´m doing an application with some syncbo T01, can i put ME-SYNC_USER too and in getlist and gedetail filter with this user?
    Thanks,

    mmmmm, i have the code of ALM_MEREP_090_GETLIST
    FUNCTION alm_merep_090_getlist.
    *"*"Lokale Schnittstelle:
    *"  TABLES
    *"      CUSTOMIZED_USERS STRUCTURE  MAM_20_USER_DATA
    *"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
    * SyncBO 090 = Userspecific customizing
    * The returntable holds a list of all users set up in
    * MAM customizing
    * If users are already passed from the table, only these
    * users are selected (used for server-driven).
      DATA ls_alm_me_d997 TYPE alm_me_d997.
      DATA lv_message.                                    "#EC NEEDED Dummy
    *  DATA ls_return    TYPE bapiret2. "Not needed due to table parameter
      DATA lt_alm_me_d997 TYPE TABLE OF alm_me_d997.
      DATA ls_user_data   TYPE alm_me_user_data.
    * BAdI data
      STATICS lr_badi_cust_user TYPE REF TO if_ex_alm_me_090_cust_user.
    * Check customizing, if selection is active
      CALL FUNCTION 'ALM_ME_SELECTION_ACTIVE'
           EXPORTING
                syncbo                 = gc_syncbo_090
                method                 = gc_method_getlist
           EXCEPTIONS
                syncbo_method_inactive = 1
                OTHERS                 = 2.
      IF sy-subrc NE 1.
    * Select users
        SELECT * FROM alm_me_d997 INTO TABLE lt_alm_me_d997.
        IF sy-subrc NE 0.
    * Keine Benutzerzuordung zu MAM Szenarien gefunden
          MESSAGE e008(alm_me) INTO lv_message.
    * In case of error fill return table
          CALL FUNCTION 'ALM_ME_MESSAGE_TO_RETURN'
               TABLES
                    return = return.
    * -> Exit
          EXIT.
        ENDIF.
    * Check if table was filled from middleware
        DATA lv_lines TYPE i.
        DESCRIBE TABLE customized_users[] LINES lv_lines.
    * Get headers
    * Map the customizing table to the function module interface
    * to be sure changes on the database or interface will not
    * cause any troubles.
        LOOP AT lt_alm_me_d997 INTO ls_alm_me_d997.
    * When users are given in the table, just select them,
    * and not all users
          IF lv_lines NE 0.
            READ TABLE customized_users
              WITH KEY userid = ls_alm_me_d997-userid.
            IF sy-subrc NE 0.
    * Entry not found, continue loop without adding the data
              CONTINUE.
            else.
    * Delete the passed entry since it will be added with data below
              DELETE customized_users[] index sy-tabix.
            ENDIF.
          ENDIF. "Users where passed from middleware
    * Get the data
          CALL FUNCTION 'ALM_ME_USERCUST_HEADER'
               EXPORTING
                    customizing_user =
                       ls_alm_me_d997-userid                 "#EC DOM_EQUAL
               IMPORTING
                    user_customizing_head  = ls_user_data
               TABLES
                    return                 = return
               EXCEPTIONS
                    customizing_read_error = 1
                    OTHERS                 = 2.
          IF sy-subrc NE 0.
            MESSAGE w029(alm_me)
              WITH 'Benutzer'(001) ls_alm_me_d997-userid
              INTO lv_message.
            CALL FUNCTION 'ALM_ME_MESSAGE_TO_RETURN'
                 TABLES
                      return = return.
          ELSE.
            MOVE-CORRESPONDING ls_user_data TO customized_users.
          APPEND customized_users.
        ENDIF.
        ENDLOOP.
      ENDIF. "Standard selection active
    * Call customer BAdI
    * The BAdI can be used to select a own order list
    * or to modify the data selected.
    * The data returned in order_list must be the same
    * content as in getdetail ORDER_HEADER for the same
    * order. Therefore usually the getdetail BAdI has
    * to be implemented as well
    * iniztialize BAdI
      IF lr_badi_cust_user IS INITIAL.
        CALL METHOD cl_exithandler=>get_instance
    *    EXPORTING
    *      EXIT_NAME = 'ALM_ME_090_CUST_USER'
        CHANGING
          instance = lr_badi_cust_user.
      ENDIF.
    * call BAdI
      CALL METHOD lr_badi_cust_user->getlist
        CHANGING
          user_list = customized_users[]
          return    = return[].
    ENDFUNCTION.
    But i continue without see where fill the user...
    My application is offline, work?
    I have to add the code in my bapi getlist and getdetail no?
    The user in the middleware or in the backend have to setup in any table?
    Thanks,

  • Can't set ipv6 static address

    As the topic states, I can not setup a static IP to save my life. I've enabled ipv6, I have a hostname6.ce1 I put the hostname (madrid-ipv6) in the hostname6.ce1 file but it will not stay set.
    I've tried the addif command, and it creates a logical interface, but I can't ping out with the address that is set.
    I'm sure I am missing something, and I am new to Solaris. I've got ipv6 static addresses setup in linux with no problems. It's just Solaris 10 that is kicking my butt.
    If anyone can point me in the right direction I would be in your debt.
    Thanks!

    edit: To darren: I've tried that as well. When the system boots, it gives me the error: "Failed to assign ipv6 address to ce1" or something similar to that.
    hmmm, I've tried that, it still doesn't seem to be working. Here is my hostname6.ce1 file:
    madrid-ipv6
    addif fd01::e2/64 up
    this is the output of ifconfig -a6:
    bash-3.00# ifconfig -a6
    lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1
    inet6 ::1/128
    ce0: flags=2004841<UP,RUNNING,MULTICAST,DHCP,IPv6> mtu 1500 index 2
    inet6 fe80::203:baff:fe9b:92d/10
    ether 0:3:ba:9b:9:2d
    ce1: flags=2000840<RUNNING,MULTICAST,IPv6> mtu 1500 index 3
    inet6 fe80::203:baff:fe9b:92d/10
    ether 0:3:ba:9b:9:2d
    ce1:1: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 3
    inet6 fd01::e2/64
    and this is what I get when I ping fd01::f2:
    bash-3.00# ping fd01::f2
    ICMPv6 Address Unreachable from gateway fd01::e2
    for icmp6 from fd01::e2 to fd01::f2
    ICMPv6 Address Unreachable from gateway fd01::e2
    for icmp6 from fd01::e2 to fd01::f2
    ICMPv6 Address Unreachable from gateway fd01::e2
    for icmp6 from fd01::e2 to fd01::f2
    I've got to be missing something. This is all on a private switch that doesn't need to connect to the net. I need to connect an iscsi VTL to this sun system but the first step is to be able to ping the damn thing. I've checked the networking to make sure everything is connected. I can ping the VTL using IPV4, but not IPV6. I've checked on a linux system and it can ping the VTL over IPV6 so I know it is setup properly. This is just driving me nuts.
    Edited by: jonwheeler on Sep 11, 2008 9:47 AM

  • Can i put images on a button

    Hi i have some omages which i need to put on a button can i do that in java. I cannot use swings cause i am using java 1.1.7. can i do something using awt.
    Is there ImageButton in jdk 1.1.7 ???
    Please help me in this.
    Please post a sample code if any one can
    Thanks
    Ram

    Hi This is my actual program.
    I have some images posted and some buttons. But can i click on the images to open new files or can i put an image on a button. I donno how to use mouse click. or how do i map an image.
    Can i also mouse click on a text string???
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.event.MouseEvent;
    import java.applet.*;
    import java.io.*;
    import java.lang.String;
    public class chemviz extends Frame implements ActionListener
         private Button offwaltz, nanocad;
         private Panel PagePanel, buttonPanel;
         private Image logo;
         private Image nanocadhome, waltzhome;
         //private TextArea TextArea1;
         private String About = "About";
         private String test= "This is a Test";
         //test.setFont(new Font("Arial",Font.BOLD,12));
         public String line1 = "ChemViz (Chemistry Visualization) is an interactive chemistry program which incorporates computational chemistry simulations ";
         public String line2 = "and visualizations for use in the high school chemistry classroom. The chemistry simulations support the chemistry principles ";
         public String line3 = "teachers are trying to convey, and the visualizations allow students to see how matter interacts at an atomic level.";
         public void loadPanel()
              //ImageIcon offwaltz = new ImageIcon("images/waltzhome.jpg");
              //offwaltz = new Button(offwaltz);
              offwaltz = new Button("OffWaltz");
              offwaltz.addActionListener(this);
              nanocad = new Button("Nanocad");
              nanocad.addActionListener(this);
              buttonPanel = new Panel(new FlowLayout(FlowLayout.CENTER));
              buttonPanel.add(offwaltz);
              buttonPanel.add(nanocad);
              //TextArea1 =new TextArea(text, 10, 100);
              MenuBar mb = new MenuBar();
              setMenuBar(mb);
              Menu fileMenu = new Menu("File");
              mb.add(fileMenu);
              MenuItem exitMenuItem = new MenuItem("Exit");
              fileMenu.add(exitMenuItem);
              exitMenuItem.addActionListener(this);     
              PagePanel = new Panel();
              PagePanel.setLayout(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.anchor = GridBagConstraints.NORTH;
              c.gridwidth = 1;
              c.gridx = 0;
              c.gridy = GridBagConstraints.RELATIVE;
              c.weightx = 1;
              c.weighty = 1;
              c.insets = new Insets(0, 0, 0, 0);
              //PagePanel.add(TextArea1, c);
              //PagePanel.add(buttonPanel, c);
              setLayout(new GridBagLayout());
              add(PagePanel, c);
              PagePanel.setLocation(0, 100);
              //PagePanel.setSize(100, 100);
              setVisible(true);
         public void update(Graphics g)
              paint(g);
         public void paint (Graphics g)
              g.drawImage(logo, 0, 30, this);
              //g.drawString(About, 20,150);
              //setFont(new Font("Arial",Font.BOLD,12));
              g.drawString("About", 20,130);
              g.drawString("Tools", 70,130);
              g.drawString("Curriculum", 120,130);
              g.drawString("Resources", 200,130);
              //g.drawString("Test", 690,130);
              //g.drawString("This is a Test String", 20,130);
              g.drawString(line1, 50,175);
              g.drawString(line2, 20,200);
              g.drawString(line3, 20,225);
              g.drawRect(38,373,148,168);
              g.drawImage(nanocadhome, 40, 375, this);
              g.drawRect(248,373,148,168);
              g.drawImage(waltzhome, 250, 375, this);
              //System.out.println("Test is ending");
         public void imagePanel()
              logo = Toolkit.getDefaultToolkit().getImage("images/logo.jpg" );
              nanocadhome = Toolkit.getDefaultToolkit().getImage("images/nanocadhome.jpg" );
              waltzhome = Toolkit.getDefaultToolkit().getImage("images/waltzhome.jpg" );
         public void actionPerformed(ActionEvent e)
              String s = e.getActionCommand();
              String osCommand = "cmd /q /c start /w";
              if (e.getSource() instanceof MenuItem)
                   String menuLabel = ((MenuItem)e.getSource()).getLabel();
                   if(menuLabel.equals("Exit"))
                        dispose();
                        System.exit(0);
              if (e.getActionCommand().equals("OffWaltz"))
                   try
                        Runtime.getRuntime().exec("cmd.exe /c java -jar offwaltz.jar ");
                   catch (IOException ex)
                        System.out.println( ex.toString() );   
             if (e.getActionCommand().equals("Nanocad"))
              try
                        Runtime.getRuntime().exec("cmd.exe /c java -jar nanocad.jar ");
                   catch (IOException ex)
                        System.out.println( ex.toString() );   
         public static void main(String args[])
              chemviz frame = new chemviz();
              frame.addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent e)            
                        {               System.exit(0);        }});
                   frame.setSize(800, 600);
                   frame.imagePanel();
                   frame.loadPanel();
                   frame.setVisible(true);

  • How can I do a static TV effect with Adobe Premiere Pro CC?

    Hi,
    so this is my question. I've tried putting a static tv pattern and adding the noise effect, but it hasn't worked.
    I hope you can help me. Thanks!

    I'm running the PrPro CC. I'm a beginner, so I don't know how PrPro really works. I've tried to put an image and add the noise effect (iv'e read something about this effect) but it hasn't worked. I'm also using an static tv noise, but I think that I can manage it.
    Thanks!

  • Can I make a static screen saver for an LCD screen?

    Can I make a static screen saver for an LCD screen? In researching screensavers the other day, I read an article saying that moving images were no longer necessary since that was important for cathode monitors and LEDs have no such problems but the iMacs are LCD. Do LCD get "Burn in"?
    I need to know as I am making wallpaper and screensvers for the company I work at.

    LCD's normally are not affected by any burn in, just use the computer. It's a wise idea to put the display to sleep when it's not in use.  You can set the setting in System Preferences - Energy Saver. I set my display to sleep after 15 minutes of not being used and it goes black, I've done this for 8+ years and have never had any display issues.

  • Can I put more than one user under one Apple ID account. I want to let other family members use imessage on their own Apple device. Or is there another way to get this end result?

    Can I put more than one user under one Apple ID account. I want to let other family members use imessage on their own Apple device. Or is there another way to get this end result?

    You can seach the net for solutions like this one http://appletvvpn.com/how-to-connect-apple-tv-2-to-vpn/ another idea is to use a PC as the control and fit that with a wireless card and set up a ad hoc wireless network that the Apple TV uses. 

  • How can i put apps from one ipod to a new ipod?

    how can i put apps from one ipod to a new ipod?

    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device

  • I can not put the data of a field(LONG RAW) consulted into a item of a data block

    I want to query a field that is LONG RAW(it's a image) and put the data into a item of a data block (in Forms Builder), when i write ":BLOCK.FOTO:=vfoto" i recieve this errors: "bad bind variable ....". How can i put the data of field of my DB and put the data in a item of a data block(in Forms Builder)?.
    I can store a image in a table of my DB, but i want to query a image stored in my DB and put it into anothers table, all this on FORMS BUILDER.

    You have to base the image item on a base table and use EXECUTE_QUERY on that block. You can't do a direct select in PL/SQL into the item

  • Can I put a amd 64 X2 3800+ on a motherboard msi K8N neo2 platinium ?

    hello
    I'm sorry for my bad english but I'm french ....
    can I put a amd 64 X2 (dual core) 3800+ on a motherboard msi K8N neo2 platinium ?
    Which is the highest processor which I can put on this mothercard ?
    thanks well for your help
    @+

    I'm sorry but I dont find the info on the msi website. I listened it ! but I don't know the adress that you give me.
    thanks well for the adress : 
    but I don't know if it's e4 or e6 or manchester .... if you help me for that proc :
    http://cgi.ebay.fr/processeur-AMD-Athlon-64-X2-dual-core-3800-socket-939_W0QQitemZ290129683087QQihZ019QQcategoryZ80141QQssPageNameZWDVWQQrdZ1QQcmdZViewItem
    and that : http://cgi.ebay.fr/AMD-Athlon-64-X2-4800-socket-939_W0QQitemZ190124445607QQihZ009QQcategoryZ80141QQssPageNameZWDVWQQrdZ1QQcmdZViewItem
    and that :
    http://cgi.ebay.fr/AMD-ATHLON-64-X2-4200-4-4-GHZ-1MB-CACHE-939-DUAL-CORE_W0QQitemZ270133637708QQihZ017QQcategoryZ80141QQssPageNameZWDVWQQrdZ1QQcmdZViewItem
    I don't want to make a error ....
    thanks very well for your help
    @+

  • How can I put my icloud photos to camera roll or photo stream?

    I got a nee iphone, i backed up everything and restored it into mu new iphone, but the pictures didn't restore so i did it manually but now on my phone i got different albums icloud photo stream and camera roll. How can i put the icloud picture into camera roll or photo stream. Any ideas?? On my old iphone ive deleted everything.

    Hello Ozzie94,
    Thanks for the additional information. The camera roll is designed for photos taken on your device, or saved images from Mail and other applications. Photos synced from a computer are organized into their own album(s):
    View photos and videos - iPhone
    http://help.apple.com/iphone/7/#/iph3d267610
    - Camera Roll—photos and videos you took on iPhone, or saved from an email, text message, webpage, or screenshot
    - Shared photos and videos—Photos and videos that you’ve shared with iCloud Photo Sharing or that others have shared with you (see iCloud Photo Sharing)
    - Photos and videos synced from your computer (see Sync with iTunes)
    Additionally, you may find more information by using another one of Apple's support resources - https://getsupport.apple.com
    Thanks,
    Matt M.

  • I downloaded a movie to the wrong library by accident. now i can't put the movie on my husband's ipod because it says it can only sync to one library at a time. how do i fix this? i don't want to get rid of the old videos, i just want to add new ones

    i really don't know what i did wrong. i logged into itunes using my husband's id, then bought some movies. but for some reason, it downloaded them to my library, not his. now i can't put them on the ipod. is there any way to get them out of my library and into his library? i tried home sharing, but it still won't let me sync them to the ipod

    Copy the movie from the current library to the correct library.
    iDevices can only sync to one library at a time.

  • Can I put a Moshi Mini DisplayPort to HDMI Adapter (with audio) in a thunderbolt port in the new macBook Pro

    can I put a Moshi Mini DisplayPort to HDMI Adapter (with audio) in a thunderbolt port in the new macBook Pro, will it work?

    Should work perfectly.

  • How can I put OSX 10.7 on a new Macbook Air. Maverick no longer allows "open file in a new window" and I really miss it. At the Apple Store they told me it can't be added to the new OSX 10.10 so I  want to change the OSX on the new Macbook Air and it

    I have been using a 2012 Mac pro to do HD video editing. I bought a new portable Macbook Air only to find that Maverick no longer has "open files in a new window" which I use all the time in the very large folders of video clips and royalty-free music. I asked at the Apple Store how I could get this back on the Macbook Air and they said it couldn't be done so I thought I would re-format the HD and install 10.7 on it and was notified by the Macbook Air I can't put 10.7 on that computer. Apple use to give this as an option but now they have gone more to the attitude of "Do it our way or go to ****!" In anger I went out and bought a Dell Laptop and Pinnacle Studio 17 which I have been learning to use. I have been an Apple/Mac user since 1979 and would still rather do my video editing on a Mac. Is there any way that I can force the Macbook Air to let me load in OSX 10.7 where there is still the option to  "open files in a new window" or is there a way to add this to Maverick? The experts at the Madison, WI Couldn't give me any help on this.

    Choose Preferences from the Finder menu, click on the General tab, and uncheck the box to open folders in a new tab.
    (117195)

  • I just PAID for Black eyed peas Time of my life and now iTunes says I can't put it on my iPod 5th gen ? What? Why? And how can I get it on my ipod?

    I just PAID for Black eyed peas Time of my life and now iTunes says I can't put it on my iPod 5th gen ? What? Why? And how can I get it on my ipod? And if I can't put it on my ipod how do I get my money back? I registered my ipod on iTunes, why was a song I can't put on my ipod even offered to me? What a rip?

    Because you can only synce with one iTunes library and you are switching libries by using the new computer. To nake this yyour syncing computer:
    - Move all the media(apps, music, synced video and photos etc) to the new computer.
    - Connect the iPofd yo the computer and bake a backup fo the iPod by right clicking on the iPod under Devices in iTunes and select Back Up
    - Restore the iPod from that backup.
    Note that the backup that iTunes makes doe not include media.
    To move mdia to the new computer see:
    iTunes: How to move your music to a new computer
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer

Maybe you are looking for

  • Macbook freezing when restarting to update

    I'm trying to update my 2010 Macbook Pro to the newest OS + itunes versions, but it freezes when restarting (it's showing the space screen indefinitely). Anyone has a solution, I can try? Many thanks

  • How to merge menubar and tab bar?

    Currently, the menubar and the tab bar are separate bars and therefore take up double vertical space. How can I merge them so that tabs would show to the right of the menubar? Please help. Thanks.

  • SAP Netweaver 7.01 ABAP Trial Version 的 License 问题

    大家好,我由于换了电脑,将原来的操作系统重新封装后,克隆到新电脑.ABAP Trial 的服务可以运行,但GUI登陆是提示授权检查错误,使用新的Active Hardware Key 申请的License文件后在导入时发现,License 文件中的 System Number 与原来的  System Number 不同. 请问有解决的方案吗?

  • Uninstalled chromium, tbird can't access my gmail any more. Reinstalled tbird, tells me 'username or password is incorrrect' when it is not.

    Used tbird for my gmail for years with no problem. Uninstalled chromium browser and suddenly tbird was getting a 'connection refused' message. Tried everything. Completely uninstalled/reinstalled tbird. It made no difference. I get a username or pass

  • DI Server B1WS - Look up current user?

    Hello all: I am just wondering if there is any service that allows me to look up the currently logged on user through B1WS. I was looking through the CompanyInfo and AdminInfo objects, but haven't found any propoerty that relates to the current user.