Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA Memory Management Issues
    primarykey
    data
    text
    <p>First, a little background. I am working on Management Software that pulls data from an SQL Server. I am using <code>JPA</code> to create <code>Entity</code> instances of the tables for manipulation within the management software (I've only been using <code>JPA</code> for a couple of days now). As a test, I threw together the below code to test how much memory would be taken up storing objects of their most abundant table (PeriodicalTable) which has 18,500 rows (or there abouts) and is only likely to grow;</p> <pre><code>public static void main(String[] args) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersistenceDemoPU"); EntityManager em = emf.createEntityManager(); Query query = em.createQuery("SELECT p FROM PeriodicalTable p"); //query.setMaxResults(7000); List&lt;PeriodicalTable&gt; results = query.getResultList(); PeriodicalTable storedPlayer; for (int i = 0; i &lt; results.size(); i++){ storedPlayer = results.get(i); System.out.println(storedPlayer.toString()); if (i == (results.size()-1)){System.out.println("Total results: "+(i+1)); } } em.close(); emf.close(); } </code></pre> <p>The above code throws <code>java.lang.OutOfMemoryError: Java heap space</code> even though I have raised -Xmx to 512m. I don't want to use any more memory because the computers this software will be running on only have roughly 2GB of RAM. Now, I could use <code>.setMaxResults()</code> against each query (as you can see commented out), but that's not ideal because I will need to display all of them in the final product.</p> <p>So, the question. Are there any more memory efficient methods of running toString on every Entity in a table, whilst using JPA? What are the pros and cons of these different methods? I had thought about maybe only storing a list of the String values passed by <code>.toString()</code> but can't think of a way of doing that without first using <code>.getResultList()</code> and storing the results in a list first. </p> <p>Edit: As a side, I am using Java Standard JPA and haven't looked into Hibernate or ObjectDB or anything like that. Unless their use is essential I intend to avoid learning about more technologies than is necessary.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload