1 Reply Latest reply on Mar 6, 2008 5:08 PM by wachtda.scsi.gmx.ch

    Query on each access

    wachtda.scsi.gmx.ch

      Hello


      I have a newbie problem with some of my collections!


      My Application has following objects:


      - Device
      - LogEntry (which holds a Device)


      I dont made a List of LogEntry on the Device object because there will be many many of them.


      In my bean I have a method which gives me all LogEntry from a given Device.


      On the view I loop trough a collection of devices, for each device I need to get a collection of LogEntry.



      #{deviceAction.logEntriesByDevice(device)}



      If I want to check the size of the collection (for rendering and rows) hibernate makes a database lookup on each collection access. (and this for everey device!)


      #{deviceAction.logEntriesByDevice(device).size>0}



      I think I don't get the collection the right way...
      What will be the correct implementation for this situation?
      Thankx for answers

        • 1. Re: Query on each access
          wachtda.scsi.gmx.ch

          I read in the old forum that JSF don't cache anything.
          Now I don't know how I should retrieve my Objects without forcing multiple db-querys...

          Because I loop trough my devices which can have many log entries I need to call a function which gets all log entries with the given device id.


          For the the beginning I now made a dirty hack:



          String m_OldDeviceID;
          
          public List<LogEntry> logEntriesByDevice(long p_DeviceID) {     
             // Ugly ugly hack for multiple calls
             if(p_DeviceID != m_OldDeviceID) {
                m_DeviceLogEntries = m_EM.createQuery("SELECT le FROM LogEntry le WHERE le.device.ID = :deviceID")
                                             .setParameter("deviceID", p_DeviceID)
                                             .getResultList();
          }
             m_OldDeviceID = p_DeviceID;     
             return m_DeviceLogEntries;
          }



          I think this is not the right way! Does anybody has a hint for me how I should retrieve my log entries without force multiple db queries...
          Thanx Daniel