aspose file tools*
The moose likes Object Relational Mapping and the fly likes After deleting 14 records, application hanging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "After deleting 14 records, application hanging" Watch "After deleting 14 records, application hanging" New topic
Author

After deleting 14 records, application hanging

Dhananjay Inamdar
Ranch Hand

Joined: Jan 27, 2003
Posts: 130
Hello All,

As a part of my enterprise application, I have one functionality, where code selects all of the records from one table and process them one by one. If the record gets processed succesfully then application deletes this record, if not, then set the 'Processed' flag to 'NO'.

When ever I am executing this piece of code with 300 records in the table, application select all of the records and starts processing them one by one. First 14 records getting processed properly and as per the flow records are getting deleted also from the table.

When it crosses 14th record then on 15th application processed the record but after that when it tries to delete this record application just hangs. I am not sure why application is not able to delete 15th record.

If you stop the application and restart it then again application will delete first 14 records and will stop on 15th record.

Code of my delete method is as follows

<blockquote>code:
<pre name="code" class="core">
public void delete( BatchEntry batchEntry )
{
Connection _con = null;
Statement _st = null;
try
{
_con = getHibernateSession().connection();
_st = _con.createStatement();
_st.executeQuery( "Delete from BATCH_ENTRIES where ID = " + batchEntry.getId() );
_con.commit();
}
catch ( SQLException _se )
{
try
{
_con.rollback();
}
catch ( SQLException se )
{
m_log.error( "Could not rollback DB connection", se );
}
m_log.error( "SQLException while deleting record from BATCH_ENTRIES, exception is : ", _se );
throw new FitnessRuntimeException( _se );
}
finally
{
close( _st );
close( _con );
}
}

</pre>
</blockquote>


Please do let me know if you need any more information.

Thanks
[ July 16, 2008: Message edited by: Mark Spritzler ]

Just like you, struggeling to get the right solutions!<br /> <br />Sun Certified Java Programmer 1.5<br /> <br />Target - SCWCD
Dhananjay Inamdar
Ranch Hand

Joined: Jan 27, 2003
Posts: 130
Just to add more information, on 15th time application is hanging on the following line

_st = _con.createStatement();

Of this Delete() method.

Please help me solving this problem.

Thanks in advance!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

I am confused, are you opening a statement for each delete of a record? Doesn't that seem overkill. Couldn't you come up with just one statement that deletes everything that you need in one time.

Are you sure all your connections/statements are closing, because I am assuming here that you are just running out of connections/statements because it is configured to only give you so many, and since they aren't being released, then it just waits for one.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Dhananjay Inamdar
Ranch Hand

Joined: Jan 27, 2003
Posts: 130
Hi Mark,

Thanks for the reply!

I cann't create a statement which will delete all the required records in one shot, since this is how the nature of the application. I have to select all the records from the table and process each record one-by-one. If process is succesull then delete that single record.

BUT, after reading your reply I did review my code and find out that I am closing statement and connection but not Hibernate Session. So I did close the Hibernate Session also after connection and that thing solved my problem.

Now application is not stopping after 14th record and deleting all the processed records.

Thanks once again!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: After deleting 14 records, application hanging