-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: java.lang.OutOfMemoryError result in loss of data
PostPosted: Thu Aug 19, 2004 3:01 pm 
Newbie

Joined: Fri Jul 23, 2004 12:13 am
Posts: 7
Hibernate version: 2.1.4

Name and version of the database you are using:mySQL 4.0.20 (myISAM with autocommit)


I have isolated some code in an application that results in some very bad behaviour.
The code is really incorrect, but I need to understand why it is happening.

Essentially what is happening is as follows:

1)Select * from table
2)get java.lang.OutOfMemoryError exception.
3)exception handler does a flush and closes the session.
4)"update table" commands are issued for all rows in the select's record set setting all columns to NULL thus wiping out data!

The sample code is as follows:

private List getProjectList()
{
Session session = null;
try {
session = GetSession();
return session.find("from projects"); // get all

} catch (HibernateException e) {
} catch(Throwable e) {
} finally {
try {
if( session ){
session.flush();
session.close();
)
} catch (Throwable e) {
}
}
return null;
}


public static void main(String[] args)
{

List objects = parent.getProjectList();
List objects1 = parent.getProjectList();
List objects2 = parent.getProjectList();
List objects3 = parent.getProjectList();
}


I call getProjectList() until I get the java.lang.OutOfMemoryError memory. I limit the VM's memory to 5MB to make this happen sooner.

When the session.flush() is called, many updates are issued result in a loss of data!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 3:43 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
3)exception handler does a flush and closes the session.


when an exception is catched, discard the session don't flush

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 5:29 pm 
Newbie

Joined: Fri Jul 23, 2004 12:13 am
Posts: 7
>when an exception is catched, discard the session don't flush
Anthony, This I know, that is why I said the code was incorrect.

But my question is:
Why does the flush after OUT OF MEMORY do this (see below) to the data?
The columns where NOT NULL *BEFORE* before the out of memory and flush.... This was totally unexpected.

You will notice the the VERSION column is being incremented.
The sample code *does not* modify any data.

I know how to fix this (i.e don't flush), but I just want to understand what is happening and are there other cases where hibernate might do this?


<from mysql bin log>

update PROJECTS_DB3 set version=590, userName=null, guid=null, event=null, projectName=null, ID_Secondary=null, ID_Production=null, archiveId=null, ID_Additional=null, projectTitle=null, Title_Secondary=null, Title_Production=null, Title_Archive=null, Title_Additional=null, description=null, Description_Secondary=null, Description_Sound=null, Description_Archive=null, Description_Subject=null, Description_Additional=null, comment=null, keywords=null, createDate=null, Date_Due=null, projectStartDate=null, lastModifyTime=null, Date_Completed=null, broadcastDate=null, lastBroadcastDate=null, Date_Repeat=null, NumberRepeats=0, Date_Accessed=null, Date_Archived=null, inciteIdbPath=null, ipcFilePath=null, Location_Tape=null, Location_Geographical=null, Location_Recording=null, Location_Additional=null, destinationProgram=null, destinationChannel=null, projectCreator=null, editor=null, News_Editor=null, Editor_in_Chief=null, Photographer=null, Reporter=null, Presenter=null, Participants=null, Additional_Person=null, journalist=null, assignedTo=null, Language=null, Medium=null, Format_Standards=null, Film_Type=null, Sound_Type=null, VersionInfo=null, Category=null, Addition_Info=null, projectGroup=null, status=null, Project_Priority=null, User_Project_Priority=null, projectOrigin=null, projectEventType='Project', parentProjectGuid=null, archiveStatus=null, archiveTapeId=null, archiveTapeDesc=null where dbId=1 and version=589;


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 8:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Um??

An OOME excetion occurred while Hibernate was loading data, so it has a bunch of broken objects in the session cache. This is really pretty simple to understand. The state of the session is inconsistent, so of course don't flush it.

If you just follow the well-documented exception-handling algorithm, this cannot happen.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.