I have a problem, which can probably be resolved easily, but I'm not sure how to do it. So if anyone has any tips to try, I'm all ears.
The problem is this. I have what is basically a read only database. But after I load data into it, I have certain 'derived' data that I generate and have to populate the database with.
So I Load data (no problems).
Then I run a loader program that basically goes out with Hibernate(I've tried 2.0 and 2.1b3) to the mySQL database (4.04) and grabs some data. I then parse it and need to repopulate another table. This part works with no problems.
However, when I try to populate is when I run into problems. It'll work for a while, but eventually, runs out of memory (after about 2000 entries). The code is rather simple:
Code:
private void addAuthors(String citation_id, String struct_id, String authors, Session sess)
throws HibernateException, SQLException
{
String aWord = null;
CitationAuthorMaster cit = new CitationAuthorMaster();
//Session sess;
try
{
// sess = getHibernateSession();
java.lang.Long cid = new Long(citation_id);
cit.setCitationId(cid);
cit.setStructId(struct_id);
cit.setAuthors(authors);
// Commit the data
sess.save(cit);
sess.flush();
sess.connection().commit();
//sess.close();
}
catch (HibernateException e)
{
e.printStackTrace();
}
catch (SQLException e1)
{
e1.printStackTrace();
}
}
I have a session that is open in the function that calls this function. I've tried multiple things, including closing the session every 250 entries or whatever. I still get the problem (in fact, it happens quicker). I've tried using the evict statement below the connection().commit() statement above. No luck.
When I run memory profilers, I can see that java.lang.reflection has A LOT of bytes that it is allocating, but only a few that it is using. The calling class is a getting the hibernate. So basically, each set call, or creation of a session, allocates a lot of bytes, stops using them, but never releases control to be garbage collected.
I don't know if using JTA would help or not, it's about the only thing I haven't tried I think. But I think there is a leak.
Again, if anyone has had this problem, or has any ideas, please let me know.
Thank You,
Jeff