newbie random outofmemory exceptions

M

Mark

i haven't touched java since university and most of my current job is taken up
with writing custom persistence frameworks for data entry applications in c++,
so after discovering jpa (which looks like a godsend) i wrote a really simple
program to test it out (see below).

using netbeans i generated the jpa entities (24 in total), edited them to remove
incorrect @Id annotations, setters for primary keys, and recursive relations
except in the case of a parent-child relationship.

the problem is that after running for about 5 minutes i get "Exception in thread
"main" java.lang.OutOfMemoryError: Java heap space" in random places. i
increased the minimum heap size to 128mb and maximum to 256mb from their
defaults which had no effect. the little memory indicator in netbeans that
displays when debugging doesn't go over 60mb (out of 80mb in total). jprobe
shows out of 80mb memory usage the JVM takes about 50mb and the test program
only takes 30mb.

is there something i'm doing wrong? or something i can do to tell what's taking
up all the heap space?

TIA

public void test() {

try {
EntityManager em = emf.createEntityManager();
Connection con = DriverManager.getConnection("connection string");
Statement st = con.createStatement();
Query q = em.createQuery("select p from Product p" +
" where p.productid = :productid");
ResultSet rs = st.executeQuery("select productid from product order
by productid");

while (rs.next()) {
int productid = rs.getInt("PRODUCTID");
q.setParameter("productid", productid);
Product p = (Product)q.getSingleResult();
}

st.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}

}
 

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top