Accessing objects after closing the PersistenceManager

I have a session bean which returns a collection of objects obtained from a
query. The problem is if I close my PersistenceManager in the session bean
method, I can't access the objects. What will happen if I don't close it?
Won't I have a memory leak? I'm curious if I'm missing something. Here is
my code, I cut out most of it. The println's work fine if I comment out the
pm.close().
public Collection searchFlights(AirportCode from, AirportCode to, Calendar
calendar, int passengers) {
PersistenceManager pm = null;
try {
pm = factory.getPersistenceManager();
c = (Collection) q.executeWithMap(p);
} finally {
pm.close();
Iterator i = c.iterator();
while (i.hasNext()) {
System.out.println("Flight = " + (Flight) i.next());
return c;

Michael-
Firstly, you do not need to obtain and close the PersistenceManager in
each method if you are using a stateful session bean. However, if you
are using a stateless session bean, section 16.1.1 mandates:
At the end of the business method, the PersistenceManager instance
must be closed. This allows the transaction completion code in the
PersistenceManager to free the instance and return it to the
available pool in the PersistenceManagerFactory.
Now, as it happens, we don't pool PersistenceManagers, and I am fairly
sure that it would work fine if you didn't close it, but it is always
good to respect the spec when writing portable code.
I suspect that the problem that you might be seeing is that your session
bean is serializing the Collection to return to the client. Note that
the full closure of serializable fields can wind up being a huge
performance hit (e.g., the entire object graph in the database may be
instantiated). Bear this in mind when your code is serializing a PC.
To get around the problem, you could throw in a quick serialization
right before you close the PM. E.g.:
new ObjectOutputStream (new ByteArrayOutputStream ()).writeObject (c);
This will be a performance hit, but I doubt that it will be any more so
than sending the entire serialized graph over the network.
In article <[email protected]>, Michael wrote:
I have a session bean which returns a collection of objects obtained from a
query. The problem is if I close my PersistenceManager in the session bean
method, I can't access the objects. What will happen if I don't close it?
Won't I have a memory leak? I'm curious if I'm missing something. Here is
my code, I cut out most of it. The println's work fine if I comment out the
pm.close().
public Collection searchFlights(AirportCode from, AirportCode to, Calendar
calendar, int passengers) {
PersistenceManager pm = null;
try {
pm = factory.getPersistenceManager();
c = (Collection) q.executeWithMap(p);
} finally {
pm.close();
Iterator i = c.iterator();
while (i.hasNext()) {
System.out.println("Flight = " + (Flight) i.next());
return c;
Marc Prud'hommeaux [email protected]
SolarMetric Inc. http://www.solarmetric.com

Similar Messages

  • MissingResourceException when I iterator a collection after closing the PM

    I retrieve a collection, call pm.retrieveAll on it, and then close the PM.
    When I try to iterator over the collection, I get a
    MissingResourceException. I can't figure out why I'm getting the exception,
    if I do a retrieveAll it should retrieve all the fields of all the objects
    in the collection. It's as if there is a rule "Thou shall not iterator over
    a collection after closing the PM". Is this true?
    java.util.MissingResourceException: Can't find resource for bundle
    java.util.PropertyResourceBundle, key resultlist-closed
    at java.util.ResourceBundle.getObject(ResourceBundle.java:314)
    at java.util.ResourceBundle.getString(ResourceBundle.java:274)
    at serp.util.Localizer.get(Localizer.java:270)
    at serp.util.Localizer.get(Localizer.java:121)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.checkClosed(LazyResult
    List.java:349)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.listIterator(LazyResul
    tList.java:403)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.iterator(LazyResultLis
    t.java:397)
    at
    com.verideon.siteguard.services.SchedulerService.getMonitorsToRun(SchedulerS
    ervice.java:103)
    at
    com.verideon.siteguard.services.SchedulerService.schedule(SchedulerService.j
    ava:59)
    at
    com.verideon.siteguard.web.util.TimerServlet$scheduleTask.run(TimerServlet.j
    ava:84)
    at java.util.TimerThread.mainLoop(Timer.java:432)
    at java.util.TimerThread.run(Timer.java:382)
    Here is my code:
    private Collection getMonitorsToRun() {
    Collection c = new LinkedList();
    PersistenceManager pm = null;
    try {
    pm = JDOFactory.getPersistenceManager();
    Extent extent = pm.getExtent(Monitor.class, true);
    String filter = "nextDate <= now";
    Query q = pm.newQuery(extent, filter);
    q.declareParameters("java.util.Date now");
    q.setOrdering("nextDate ascending");
    Hashtable p = new Hashtable();
    p.put("now", new Date());
    c = (Collection) q.executeWithMap(p);
    pm.retrieveAll(c);
    } catch (JDOException e) {
    log.warn("Received JDO Exception while retrieving Monitors " + e);
    } finally {
    pm.close();
    log.debug("Retrieved " + c.size() + " Monitors ready to be ran.");
    Iterator i = c.iterator();
    while (i.hasNext()) {
    Monitor m = (Monitor) i.next();
    log.debug("m id = " + m.getId());
    return c;

    It appears to be a query in which case, yes, a Query result Collection cannot be iterated over.
    The simple way to bypass this is to transfer the results to a non-closing Collection.
    Collection results = (Collection) q.execute ();
    results = new LinkedList (results);
    pm.retrieveAll (results);
    pm.close ();
    On Thu, 27 Feb 2003 14:49:17 +0100, Michael Mattox wrote:
    I retrieve a collection, call pm.retrieveAll on it, and then close the PM.
    When I try to iterator over the collection, I get a
    MissingResourceException. I can't figure out why I'm getting the exception,
    if I do a retrieveAll it should retrieve all the fields of all the objects
    in the collection. It's as if there is a rule "Thou shall not iterator over
    a collection after closing the PM". Is this true?
    java.util.MissingResourceException: Can't find resource for bundle
    java.util.PropertyResourceBundle, key resultlist-closed
    at java.util.ResourceBundle.getObject(ResourceBundle.java:314)
    at java.util.ResourceBundle.getString(ResourceBundle.java:274)
    at serp.util.Localizer.get(Localizer.java:270)
    at serp.util.Localizer.get(Localizer.java:121)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.checkClosed(LazyResult
    List.java:349)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.listIterator(LazyResul
    tList.java:403)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.LazyResultList.iterator(LazyResultLis
    t.java:397)
    at
    com.verideon.siteguard.services.SchedulerService.getMonitorsToRun(SchedulerS
    ervice.java:103)
    at
    com.verideon.siteguard.services.SchedulerService.schedule(SchedulerService.j
    ava:59)
    at
    com.verideon.siteguard.web.util.TimerServlet$scheduleTask.run(TimerServlet.j
    ava:84)
    at java.util.TimerThread.mainLoop(Timer.java:432)
    at java.util.TimerThread.run(Timer.java:382)
    Here is my code:
    private Collection getMonitorsToRun() {
    Collection c = new LinkedList();
    PersistenceManager pm = null;
    try {
    pm = JDOFactory.getPersistenceManager();
    Extent extent = pm.getExtent(Monitor.class, true);
    String filter = "nextDate <= now";
    Query q = pm.newQuery(extent, filter);
    q.declareParameters("java.util.Date now");
    q.setOrdering("nextDate ascending");
    Hashtable p = new Hashtable();
    p.put("now", new Date());
    c = (Collection) q.executeWithMap(p);
    pm.retrieveAll(c);
    } catch (JDOException e) {
    log.warn("Received JDO Exception while retrieving Monitors " + e);
    } finally {
    pm.close();
    log.debug("Retrieved " + c.size() + " Monitors ready to be ran.");
    Iterator i = c.iterator();
    while (i.hasNext()) {
    Monitor m = (Monitor) i.next();
    log.debug("m id = " + m.getId());
    return c;
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • How to Direct control to application's window after closing the popup?

    Hi,
    I am using 10.1.3. In my application I am unable to direct control to application's window after closing the popup, if I open any other window at the same time.
    For more info see the below step:-
    -> Open any popup in my application.
    -> Open any new window (lets say Google.com).
    -> Now restore popup on Google window.
    -> Now close popup
              - control goes to Google window but not the parent application window.
    How to direct control to the parent window?
    Can anybody help me regarding this?
    Thanx...Abhijit

    Hi Abhijit,
    You can do this using Javascript alone. Below are the two sample files I created.
    main.html_
    <html>
    <head>
      <title>Testing popup</title>
      <script type="text/javascript">
      function openPopup() {
        window.open("popup.html");
      </script>
    </head>
    <body>
      <a hr_ef="javascript:openPopup()">Open popup</a>
      <input id="something" name="something" type="text" value="something">
    </body>
    </html>
    Note: hr_ef should be href. The code tags are messing with the link.
    popup.html_
    <html>
    <head>
      <title>This is the popup window</title>
      <script type="text/javascript">
      function goToMain() {
        window.opener.something.focus();
      </script>
    </head>
    <body onunload="goToMain()">
      This is the popup window. Close this window to return to main window.
    </body>
    </html>The idea is to call a javascript function in the popup window that tries to focus on an object (eg. InputText) in the main html.
    Although, one point to take note is the naming of html objects by by these ADF UI Components. If you named your form id as "*form1*" and input text id as "*something*", your input text id will end up as "*form1:something*".
    Therefore, you will have to tweak the code above to the following:
    <script type="text/javascript">
    function goToMain() {
      window.opener.form1['form1:something'].focus();
    </script>Regards,
    Chan Kelwin

  • Refreshing Entity Objects after Altering the table

    Hi,
    My Entity Object is based on a table... and View Objects on the Entity Objects. Now if I alter the table (just changing the width of the column), that change is not visible on the Entity Object. Is there any way I can automatically refresh the Entity Objects after altering the table(only column width is changed).
    (Changes made to Entity Objects manually are reflected in the View Object correctly.)
    Regards
    Faiyaz

    'changing the width of the column' means changing the size of the column in the table description in the database. For e.g.. In the original table I had a column OIL_KEY NUMBER(6). Now I change the column to be of size 12 i.e. OIL_KEY NUMBER(12). This does not get refreshed in the Entity Object.

  • 'You can post in new year only after closing the previous year

    Hello Experts,
    I am also getting same error while executing depreciation run AFAB ''You can post in new year only after closing the previous year''.
    I found one OSS Note 18800 and it is saying solution as below ...
    At the first depreciation posting in the new fiscal year after a shortened fiscal year, the fiscal year variants must, in all cases, still be entered in asset customizing and in FI customizing for the affected company code. If necessary, all periods for the following fiscal year must be maintained with the variant of the shortened fiscal year.
    Up to 2.2D the following correction must also be installed:
    Please carry out the syntax check only in main program SAPLAFAR.
    But in my case there is no shortended fiscal year.
    Can I apply this OSS note correction instructions ?
    Please suggest me.

    Hi
    I don't think so. Moreover that is applicable till 2.2D.
    Moreover depreciation is to be run for all periods you have not run earlier. Please check upto which period dep run has happened. Thereafter close the fiscal years in order thro AJAB.
    S Jayaram

  • I have customized my Firefox toolbar. After closing the browser and then reopening it, the toolbar has returned to the way it was before I customized it. How do I get my customization of the toolbar to become permanent?

    I have customized my Firefox toolbar several times. After closing the browser and then reopening it, the toolbar has returned to the way it was before I customized it each time. How do I get my customization of the toolbar to become permanent?
    It has occurred with Firefox 4.0.1 and 5.0

    see http://kb.mozillazine.org/Corrupt_localstore.rdf
    Take a picture of your toolbars so you can easily reconstruct them from the default after solving the the problem.
    If it happens to you it will probably happen again in the future so you might want to keep some copies of your modified localstore.rdf file so you can delete the bad one and rename one of the replacements in waiting. Saving, copying and renaming must be done with Firefox down, of course.

  • ITunes 10.5.3 restarts itself after closing the program. How do I fix this?

    iTunes 10.5.3 restarts itself after closing the program. How do I fix this?
    Windows 7 64bit Ultimate
    iTunes 10.5.3 64bit

    I've had this problem on my Windows XP for years. it's been around, unsolved, or no solutions in these forums.
    It keeps reminding me why Apple will never be the primary office computer company. Anyone running a business cannot have software running that will not behave, won't shut down, or behaves without any explanation, and this problem has no explanation, or solution that I can find except to use task manager to kill the process and only use iTunes when I'm expecting to shut down or kill the process.

  • SAPgui.exe is running even after closing the GUI components

    Hello All,
    Even after closing the SAP GUI components like Bex, WAD or RSA1 etc... i am able to see these processes are running under the Task Manager--> Processes....
    even if i try to restart the system, error messages are occuring...saying that SAP is still opend...
    Why it is happening, any ideas?
    Thanks,
    Ravi

    Hi Dirk,
    Thanks for your infomation. Infact, apart from this problem, i have the problem with saving the webtemplate. As it is taking much time to save a template after modifications, i had to terminate the wad process. It seems above 2 problems are related....any ideas?
    Thanks
    ravi
    Message was edited by: Ravi Pasumarty

  • Apps Tabs get don't reload after closing the firefox

    I just today tried to use apps tab. I set some links as apps tab and then closed the firefox. When i stared it again the apps tab were not there anymore. However according to this release the apps tab should be retained even after closing the firefox

    Go to about:config (enter it in the address bar), and find '''browser.showQuitWarning''' and set it to '''true'''. This will make Firefox ask you each time if you want to save your session to restore the next time you open it, like in 3

  • Depreciation run problem."You can only post in new year after closing the"

    Hi,
    We are implementing Asset accounting to one of our co code.New Assets were created in Jan and when I tried to Post depreciation for Jan, I get an error log that says "You can only post in new year after closing the previous year."
    When i double click on error message.
    Diagnosis
    You want to post in a new fiscal year. However, a posting must have been made in the last period in the previous fiscal year before you can do this.
    Procedure
    Post to the last period in the previous year first.
    So I went ahead and opened the previous year, posted the depreciation, closed the year and tried to post Period 1 again, but still get the same error.
    Why do I need to post the previous period if I just created the assets in this period?
    I Have completed AJRW, AJAB also.
    I think it may be a problem with Table. Please suggest me.
    Thank you

    Hi,
    Please check the following :-
    1. Check the Last Closed year in your Asset Accounting.
    2. Check the Last Depreciation Posted in Your Asset Accounting.
    These 2 menus are available in "Data Transfer in Fixed Asset Accounting".
    revert back to me for further actions,
    regards
    N.Kumar

  • Equium A60-692 won't restart after closing the lid

    Most annoying, the only thing I can do is hold the power button to switch off &switch back on again. Is there some combination of keys i should be pressing to bring her back form the brink after closing the lid, or is this a fault?
    Thanks

    Usually when the memory size changes, the system can recover.
    Remove the battery and AC Adapter, then remove one of the Memory Modules, and power up.

  • Premiere Pro CS 6.exe stays active after closing the program

    I am experiencing a problem with Premiere Pro CS 6.03. When I close the program, the second monitor would not return to desktop (it stays a black screen). The premiere pro cs.exe is active in taskmanager. Only after I end the exe process would the second monitor return to desktop. I am not using any third party hardware, only Adobe player for second monitor out. This problem occurs often, but not every time I use Premiere. I have never experienced this problem in Premiere Pro CS 5.03, which is still installed on the same PC. The technical Spec is: Intel 3930K, 32 GB RAM, GTX 560, Windows 7 Professional 64 bit. I have tried to toggle between different NVidia drivers, but with no effect.
    Any help would be appreciated!

    I've had the process stay open after closing the program as well, but only on one of my two machines.  For me, the 6.0.3 update seemed to correct the issue.  Not sure why it's still happening in your case.

  • Asset You can only post in new  year after closing the previous year

    Hi Experts,
    I am getting below error while running the depriciation:
    You can only post in new  year after closing the previous year.
    Message no. AA687
    Diagnosis
    You want to post in a new fiscal year. However, a posting must have been made in the last period in the previous fiscal year before you can do this.
    Procedure
    Post to the last period in the previous year first.
    Note : I closed FY09, even though there were no assets in it at the time.  The first  asset was capitalized on 12/29/09 (clearly in FY10).  I tried closing FY09 again and got the messege  No year-end close is necessary for company code XXXX .
    Could you please any one help me on this.
    Thanks In Adwance
    Regards,
    Saritha.

    Hi Saritha,
    Please check the following settings:                                                                               
    o Is there one ore more years since the last depr. run?                                                                               
    Solution: in this case an entry must be made into the table TABA. 
                      Note 144441  gives a solution to make a "Dummy-entry".                                                                               
    o If there was never a depreciation run, the there must be 000/0000 in
      TABA and T093D.                                                                               
    Solution: please take the report from the note  Note 144441           
                      and put the values  000/0000 in this fields.                                                                               
    o Do you  have a non-calendar fiscal year (e.g. 2009/10)? In this case
        you should have in the field T093D-AFBLG the year 2010.             
        Solution: Correction with note 26073                              
    regards Bernhard

  • Refresh the table after closing the Popup iView

    Hi all,
    I have list of survey in my table. In that table i have toolbar button(DELETE) for deleting the survey. While deleting the survey it asks the confirmation. If we click Ok it delete the selected survey and close the popup also. what I want is I should refresh the table after closing the Popup.How can i achieve this?
    Help me in this regard.
    Thanks & Regards,
    Hemalatha J

    Hi Hema,
    Check this link.
    Visual Composer - You can do anything....
    In this blog, they are used 'Refresh' Button and a Hidden 'Plain text' message to solve this problem. If you are satisfy with this you can take this solution.
    Or you can try to trigger the 'Submit' action of 'Input form' once again from the 'Popup window' when the 'Delete' button is clicked.
    Hope it helps...
    Regards
    Basheer
    Edited by: Basheer on Dec 23, 2008 8:03 PM

  • Backend BSP session not closing on server after closing the window

    Hi All,
    We have SAP EP (7.0 SP21) and there is a BSP transaction ivew (Interaction Center ) intergrated in the portal. The issue is when the user performs any transactions inside the BSP and then closes the browser, session remains on the server till the timeout. Is there a way to end those sessions on server after closing the browser immediately?
    Portal domain : xx.mycomp.com
    ABAP system domain :mycom.com
    Should the domains be same for the DSM of Portal to work or is there any solution that can be considered.
    regards
    Uday

    Hi Uday,
    These are the main issues that can cause issues with DSM:
    JavaScript Origin Policy:
    Scripting
    between different domains is not allowed because of “JavaScript origin policy”.
    Also
    communication between mixed protocols (http\https) is forbidden.
    Therefore
    the portal server and the content server must be on the same domain and must
    use the same protocol.
    For
    detailed explanation see:
    http://mozilla.org/projects/security/components/same-origin.html
    Popup Blocker:
    •Popup blockers may cause troubles
    in relation with SRA feature.
    •Terminator handles notifications in
    new window when current window is being destroyed (logoff, closing browser
    window) – popup blocker prevents the opening of new window, hence no session
    handling performed.
    please also check SAP Note #596698 for more information typical problems and troubleshooting.
    In general, the 2 domains should be the same.
    xxx.mycomp.com, meaning that first part of the url can change but what comes after should be the same domain.
    Best regards,
    Etay

Maybe you are looking for

  • MAC iPod video converting program (that does more than one at a time?)

    hey i am trying to find a free or paid for program that will convert my videos for my ipod for mac. i have the mpeg streamclip but it only does one video at a time and i have about 600 music videos i'm trying to do. any input? thanks

  • Mac Pro and Raid and boot camp.

    Hi. I was not sure where to ask this exactly but here is the question. I have 3 500gig drives. 2 are setup on a striped raid as the start up disk with the Mac OS. I wanted to setup the 3rd drive with Vista using Boot Camp. Reading the threads I was u

  • Populating a pdf from database with ASP

    Hi, I have been tasked to see if it is possible to fill in http://www.uses.doleta.gov/pdf/eta9061.pdf this government form and several others dynamically from a database. Does anyone have an idea if it can be done via ASP or am I looking at recreatin

  • Problem using FM 'RH_READ_INFTY'

    Hi, I have a problem when i try to use 'RH_READ_INFTY' with some infotypes, as 1035. I'm doing this as follows: lt_it1035 LIKE hrp1035 OCCURS 0 WITH HEADER LINE CALL FUNCTION 'RH_READ_INFTY'        EXPORTING          plvar                = '01'      

  • Scheduling tasks created in Oracle Projects

    Is it possible to use Advanced Scheduler/Field Service to schedule tasks created in Oracle Projects? How can I achieve this integration?